i need help in adding facebook share into my ios application - swift

i am trying to add facebook share dialog into my ios application and i found the official page from facebook on how to do it, but i run into a problem about ContentProtocol. i dont know what that is. here is the link to the guidence that i use . it is pretty straight forward. basically just install the pod facebookshare, import it and add few line of code, but i got problem on 'myContent'
here is the code
import FacebookShare
let shareDialog = ShareDialog(content: myContent)
shareDialog.mode = .Native
shareDialog.failsOnInvalidData = true
shareDialog.completion = { result in
// Handle share results
}
try shareDialog.show()
here is the link
https://developers.facebook.com/docs/swift/sharing/share-dialog
what should i put in the myContent?

I guess next link is explained what you can use as content and how to use it
Content-types
(From documentation) Currently, the Facebook SDK for Swift can share 4 different kinds of content:
Links - Represented by the LinkShareContent object.
Photos - Represented by the PhotoShareContent object.
Videos - Represented by the VideoShareContent object.
Open Graph - Represented by the OpenGraphShareContent object.

you can use FBSDKShareLinkContent
let content : FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: "//URL")
content.contentTitle = "MyApp"
content.contentDescription = "//Desc"
content.imageURL = NSURL(string:"//Image URL")

Related

Dynamic Links not working iOS 15.1 Facebook Swift

Firebase Dynamic Links not working iOS 15.1 for Facebook but working perfectly iOS 14.1. I have tried lot of changes with Dynamic Link parameters. I have checked all parameter configured correctly in the Firebase account and Dynamic link like App BundleId, AppStoreID, AppID and all others parameters.
For iOS 14.1
User post a dynamic link on facebook as a post. When user click on then facebook post redirect to automatically in the app.
For iOS 15.1
User post a dynamic link on facebook as post. When user click on facebook post, the user redirect default Website which i set in the dynamic link url.
User post a dynamic link on facebook as post. When user click on facebook post, the user redirect default Website which i set in the dynamic link url.
Code:-
func createLinkShare1(dynamicLinksDomainURIPrefix:String,link:URL) {
let appBundleID = AppInformation.AppBundleId
if let linkBuilder = DynamicLinkComponents(link: link, domainURIPrefix: dynamicLinksDomainURIPrefix) {
linkBuilder.navigationInfoParameters = DynamicLinkNavigationInfoParameters()
linkBuilder.navigationInfoParameters?.isForcedRedirectEnabled = true
linkBuilder.iOSParameters = DynamicLinkIOSParameters(bundleID: appBundleID)
linkBuilder.iOSParameters?.appStoreID = AppInformation.AppStoreId
linkBuilder.iOSParameters?.minimumAppVersion = AppInformation.AppMinimumVersion
linkBuilder.androidParameters = DynamicLinkAndroidParameters(packageName: appBundleID)
linkBuilder.androidParameters?.minimumVersion = 0
linkBuilder.socialMetaTagParameters = DynamicLinkSocialMetaTagParameters()
linkBuilder.socialMetaTagParameters!.title = "Testing "
linkBuilder.socialMetaTagParameters!.descriptionText = "Invite You"
guard let longDynamicLink = linkBuilder.url else {
print("ERROR in linkBuilder")
return
}
DynamicLinkComponents.shortenURL(longDynamicLink, options: nil) { url, warnings, error in
if let error = error {
print("error shortening link: \(error.localizedDescription)")
return
}
if let url = url {
print("Share Url = ",url)
return
}
}
}
}
Firebase Dynamic Links not working Every Time Open Custom WebView (Redirection issue) Swift
Please check above code and let me know if i'm doing wrong anything, please correct me.
Can someone please explain to me how to show popup or deep working as expected in the Facebook case in the iOS 15., I've tried to with above code but no results yet.
Any help would be greatly appreciated.
Thanks in advance.

How to show the path of a workout using Facebook Open Graph Stories in iOS - Result is different on Facebook App versus iPhone Browser

I have this code to share workout data on Facebook. My intention is to eventually show a path of the run/walk. But I have this confusion at the moment. If I execute this code and look at my Facebook page on either iOS Facebook App, or any browser on a computer (Mac for example) I see only the distance and some other information. But when I look at my post on a browser on an iOS device (logged in my Facebook account on either Safari or Chrome on iPhone) I see a map (See images attached). My question is why is there a difference on the look of the post depending on how I view it? And how can I show the map on the post to the Facebook App? I am using the latest Facebook SDK for iOS: Version 4.28.0
func shareOnFacebook () {
// Create an object
let properties = ["og:type": "fitness.course",
"og:title": "Title",
"og:description": "Description",
"fitness:duration:value": 1200,
"fitness:duration:units": "s",
"fitness:distance:value": 4.3,
"fitness:distance:units": "mi",
"fitness:metrics:location:latitude": 36.9926439,
"fitness:metrics:location:longitude": -102.0419088,
"fitness:metrics:location:altitude" :42,
"fitness:metrics:timestamp" :"2017-11-18T00:00",
"fitness:metrics:distance:value" : 0,
"fitness:metrics:distance:units":"mi" ,
"fitness:metrics:pace:value" :0,
"fitness:metrics:pace:units" :"s/m",
"fitness:metrics:calories":0] as [String : Any]
let object = FBSDKShareOpenGraphObject(properties: properties)
// Create an action
let action = FBSDKShareOpenGraphAction()
action.actionType = "fitness.run"
action.setObject(object, forKey: "fitness:course")
// Create the content
let content = FBSDKShareOpenGraphContent()
content.action = action
content.previewPropertyName = "fitness:course"
let shareDialog = FBSDKShareDialog()
shareDialog.fromViewController = self
shareDialog.shareContent = content
if shareDialog.canShow() {
shareDialog.show()
}
}

Need to create xul based frame in firefox extension build using xul

I want to create xul based frame in one of my firefox extension. The frame should look like https://developer.mozilla.org/en-US/Add-ons/SDK/Low-Level_APIs/ui_frame
or
how to use below node js code in xul:
var { Frame } = require("sdk/ui/frame");
var frame = new Frame({
url: "./city-info.html"
});
In node.js, its working fine, but I dont know how to create the same thing with xul. Anybody can help?
thanks in advance.
You have provided very little detail as to what you desire. If all that you desire is to create an <iframe> in which you can load HTML content, then something along the lines of the following will do so:
//The URL of the HTML you desire to load.
let chromeUrl = '[Some URL here]';
//Whatever element you want the iframe placed under.
let parentEl = document.getElementById('foo');
//* Overlay and bootstrap (from almost any context/scope):
Components.utils.import('resource://gre/modules/Services.jsm');//Services
let activeWindow = Services.wm.getMostRecentWindow('navigator:browser');
//*/
let mainDocument = activeWindow.document;
//Create the <iframe> use
//mainDocument for the XUL namespace.
let iframeEl;
if(options.useBrowser){
iframeEl = mainDocument.createElement('browser');
} else {
iframeEl = mainDocument.createElement('iframe');
}
iframeEl.id = id;
iframeEl.setAttribute('src',chromeUrl);
iframeEl.setAttribute("tooltip", "aHTMLTooltip");
iframeEl.setAttribute("autocompleteenabled", true);
iframeEl.setAttribute("autocompletepopup", "PopupAutoComplete");
iframeEl.setAttribute("disablehistory",true);
iframeEl.setAttribute('type', 'content');
parentEl.appendChild(iframeEl);
The above code was taken from my answer to Firefox SDK Add-on with a sidebar on both the right and left at the same time, which creates sidebars. One option of how those sidebars are created is to have them contain an <iframe>.
Finally I got the answer:
let chromeUrl = 'YOUR HTML PAGE URL';
Components.utils.import('resource://gre/modules/Services.jsm');//Services
let activeWindow = Services.wm.getMostRecentWindow('navigator:browser');
//*/
let mainDocument = activeWindow.document;
let iframeEl;
iframeEl = mainDocument.createElement('iframe');
iframeEl.id = "d";
iframeEl.setAttribute('src',chromeUrl);
iframeEl.setAttribute("tooltip", "aHTMLTooltip");
iframeEl.setAttribute("autocompleteenabled", true);
iframeEl.setAttribute("autocompletepopup", "PopupAutoComplete");
iframeEl.setAttribute("disablehistory",true);
iframeEl.setAttribute('type', 'content');
iframeEl.setAttribute('height', '32px');
window.document.documentElement.appendChild(iframeEl);

iOS 10 app crashes when trying to save image to photo library

I'm trying to save an image to the photo library in Swift 3 (I'm working with Xcode 8).
ViewController Code:
func shareImage(image: UIImage) {
let items = [image]
var activityVC: UIActivityViewController = UIActivityViewController(activityItems: items, applicationActivities: nil)
let excludeActivities: [UIActivityType] = [UIActivityType.airDrop,
UIActivityType.assignToContact,
UIActivityType.addToReadingList,
UIActivityType.copyToPasteboard]
activityVC.excludedActivityTypes = excludeActivities
self.present(activityVC, animated: true, completion: nil)
}
When I run the application, and click on the button to take the screenshot (converting it to image, ..., that's all working perfectly), the app asks for permission to access the photo library, I tap the "OK" button, and then the app crashes. The image is not saved in the photo library.
The only clue I get from Xcode is the following:
2016-09-28 11:24:27.216043 Ajax Kids[4143:1545362] [error] error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///var/mobile/Media/PhotoData/Photos.sqlite?readonly_shm=1 options:{
NSPersistentStoreFileProtectionKey = NSFileProtectionCompleteUntilFirstUserAuthentication;
NSReadOnlyPersistentStoreOption = 1;
NSSQLitePersistWALOption = 1;
NSSQLitePragmasOption = {
"journal_mode" = WAL;
};
} ... returned error Error Domain=NSCocoaErrorDomain Code=256 "The file couldn’t be opened." UserInfo={reason=Failed to access file: 1} with userInfo dictionary {
reason = "Failed to access file: 1";
}
2016-09-28 11:24:27.216433 Ajax Kids[4143:1545362] [Migration] Unexpected error opening persistent store <private>, cannot attempt migration <private>)
2016-09-28 11:24:27.216568 Ajax Kids[4143:1545362] [Migration] Failed to open store <private>. Requires update via assetsd (256: <private>)
Does anyone have any idea how to fix this?
Thanks in advance!
UPDATE
Sharing the image on Social Media works fine, so the problem is specified to saving the image in the photo library.
Add new records in your new InfoPlist.strings file.
<key>NSPhotoLibraryAddUsageDescription</key>
<string>$(PRODUCT_NAME)</string>
UPD: iOS 11 key
On iOS 11, there is a new property called NSPhotoLibraryAddUsageDescription, similar to NSPhotoLibraryUsageDescription. See https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html
Try to force request permissions like this:
PHPhotoLibrary.requestAuthorization { status in
if status == .authorized {
//do things
}
}
do not forget import Photos. Hope this helps.
I found the culprit in my particular case. We are using Leanplum for analytics and push notifications. The Leanplum.syncResourcesAsync method was causing the opening of the photo library to crash. It took a couple of days to find as I wasn't aware Leanplum was doing anything to hook into a user's photo library... which in itself is concerning.
We weren't using the functionality this particular method brings, so were able to just remove the method call and the photo library stopped crashing.

How to open settings app programmatically?

I'm using swift with ios 8.3. I want to open settings app from my application. I know that using the code
UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)!)
will open my app settings. But I don't want to open my app settings. I just want to open the settings app and stay in the main page. If possible, navigate to "Cellular". Is there any way to acheive this?
Try this.
if let appSettings = URL(string: UIApplication.openSettingsURLString) {
UIApplication.shared.open(appSettings, options: [:], completionHandler: nil)
}
Xcode 11.5 - iOS > 10
Update on 11-Oct-2016:
It won't work in iOS10 anymore. So far I haven't found any workaround. If you guys have any solution please let me know. thanks.
======================================
if the iOS version <= iOS9, you need set URL types:
You can do in this way:
let url:NSURL! = NSURL(string : "prefs:root=")
UIApplication.sharedApplication().openURL(url)
I have a demo on github: http://github.com/zhihuitang/SettingDemo.git
And you can find all available URLs as follows:
http://iphonedevwiki.net/index.php/Preferences.app
Preferences app registers a private URL scheme, prefs:, the list below details opening specific views 1[2]
prefs:root=General&path=About
prefs:root=General&path=ACCESSIBILITY
prefs:root=AIRPLANE_MODE
prefs:root=General&path=AUTOLOCK
prefs:root=General&path=USAGE/CELLULAR_USAGE
prefs:root=General&path=Bluetooth
prefs:root=General&path=DATE_AND_TIME
prefs:root=FACETIME
prefs:root=General
prefs:root=General&path=Keyboard
prefs:root=CASTLE
prefs:root=CASTLE&path=STORAGE_AND_BACKUP
prefs:root=General&path=INTERNATIONAL
prefs:root=LOCATION_SERVICES
prefs:root=ACCOUNT_SETTINGS
prefs:root=MUSIC
prefs:root=MUSIC&path=EQ
prefs:root=MUSIC&path=VolumeLimit
prefs:root=General&path=Network
prefs:root=NIKE_PLUS_IPOD
prefs:root=NOTES
prefs:root=NOTIFICATIONS_ID
prefs:root=Phone
prefs:root=Photos
prefs:root=General&path=ManagedConfigurationList
prefs:root=General&path=Reset
prefs:root=Sounds&path=Ringtone
prefs:root=Safari
prefs:root=General&path=Assistant
prefs:root=Sounds
prefs:root=General&path=SOFTWARE_UPDATE_LINK
prefs:root=STORE
prefs:root=TWITTER
prefs:root=General&path=USAGE
prefs:root=VIDEO
prefs:root=General&path=Network/VPN
prefs:root=Wallpaper
prefs:root=WIFI
prefs:root=INTERNET_TETHERING
hope this helpful to you.
YES, They made changes in iOS 10, Please change "prefs:" to "App-Prefs:"
guard let profileUrl = URL(string:"App-Prefs:root=General&path=ManagedConfigurationList") else {
return
}
if UIApplication.shared.canOpenURL(profileUrl) {
UIApplication.shared.open(profileUrl, completionHandler: { (success) in
print(" Profile Settings opened: \(success)")
})
}