I'm working with deep link in iOS. I am going to share a link in Facebook using `FBSDKShareLinkContent. I have created deep linking URL in Facebook like https://fb.me/****************.
I have already done AppInviteContent and it works good like this:
let content : FBSDKAppInviteContent = FBSDKAppInviteContent()
content.appLinkURL = NSURL(string: "https://fb.me/****************")!
content.appInvitePreviewImageURL = NSURL(string: "http://***.***.***.***/shareImage.png" as String)!
FBSDKAppInviteDialog.showWithContent(content, delegate: self)
Now, I am sharing link in Facebook like this:
let shareLinkContent : FBSDKShareLinkContent = FBSDKShareLinkContent()
shareLinkContent.contentURL = NSURL(string: "https://example.com/a2d69835ae")!
shareLinkContent.contentTitle = "App_Name"
shareLinkContent.contentDescription = "Description"
let dialog : FBSDKShareDialog = FBSDKShareDialog()
dialog.fromViewController = self
dialog.delegate = self
dialog.shareContent = shareLinkContent
dialog.mode = FBSDKShareDialogMode.Web
dialog.show()
How to set deep link URL (e.g. https://fb.me/****************) in this shareLinkContent.
A very apt idea is to use Branch framework for the deep linking feature. You can get to know how to use this framework from here https://branch.io/
It can be used to share your app contents to any of the social networking sites. it has the feature on universal linking and deep linking.
Remove this below code, this have been modified in latest pod version.
let dialog : FBSDKShareDialog = FBSDKShareDialog()
dialog.fromViewController = self
dialog.delegate = self
dialog.shareContent = shareLinkContent
dialog.mode = FBSDKShareDialogMode.Web
dialog.show()
Add this code will show Facebook Share dialog:
FBSDKShareDialog.show(from: self, with: shareLinkContent, delegate: self)
This will fix your FBSDK share issue.
For APP invite try some thing like this:
{
let content : FBSDKAppInviteContent = FBSDKAppInviteContent()
content.appLinkURL = NSURL(string: "https://fb.me/****************")!
content.appInvitePreviewImageURL = NSURL(string: "http://***.***.***.***/shareImage.png" as String)!
FBSDKAppInviteDialog.show(from: self, with: content, delegate: self)
}
Related
I am currently trying to enable the functionality to share a video through Facebook, however the share dialog does not show up.
Here's the code:
let video = ShareVideo(videoURL: Bundle.main.url(forResource: "Rap God", withExtension: "mp4")!)
let content = ShareVideoContent()
content.video = video
content.contentURL = Bundle.main.url(forResource: "Rap God", withExtension: "mp4")!
let dialog = ShareDialog(fromViewController: self, content: content, delegate: self)
dialog.shareContent = content
dialog.shouldFailOnDataError = true
dialog.mode = .shareSheet
dialog.fromViewController = self
dialog.show()
print(dialog.canShow)
print(dialog.canShow) is here equal to "false". Could please tell me how I could fix this?
I want to share remote URL using UIDocumentInteractionController from my app. How will I do this?
Here is my code:
let documentInteractionController = UIDocumentInteractionController.init()
documentInteractionController.name = dataUrl
documentInteractionController.delegate = self
documentInteractionController.uti = "public.content"
documentInteractionController.presentPreview(animated: true)
So this's my code for app invite :
private func inviteFriends() {
let content = FBSDKAppInviteContent()
content.appLinkURL = URL(string: "...")
content.appInvitePreviewImageURL = URL(string: "...")
FBSDKAppInviteDialog.show(from: self, with: content, delegate: nil)
}
This code works fine but if I try to add the promotional code like this :
private func inviteFriends() {
let content = FBSDKAppInviteContent()
content.appLinkURL = URL(string: "...")
content.appInvitePreviewImageURL = URL(string: "...")
content.promotionCode = "preview"
content.promotionText = "Use the *preview* code to unlock the app"
FBSDKAppInviteDialog.show(from: self, with: content, delegate: nil)
}
The the invite VC is not shown any more (the function is called but nothing is showing). What did I missed here ?
The issue was that I've used special character like * so removing it make the app works fine my final code is like this :
private func inviteFriends() {
let content = FBSDKAppInviteContent()
content.appLinkURL = URL(string: "...")
content.appInvitePreviewImageURL = URL(string: "...")
content.promotionCode = "preview"
content.promotionText = "Use the preview code to unlock the app"
FBSDKAppInviteDialog.show(from: self, with: content, delegate: nil)
}
I want to share image on Facebook, for this I do:
let photo: FBSDKSharePhoto = FBSDKSharePhoto()
photo.image = croppedImage
photo.userGenerated = true
photo.caption = "Add Your caption"
let content: FBSDKSharePhotoContent = FBSDKSharePhotoContent()
content.photos = [photo]
FBSDKShareDialog.showFromViewController(self, withContent: content, delegate: nil)
but it does not show me ShareViewController. But when I'm trying this code:
let content: FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: "http://")
content.contentTitle = "App Testing"
content.contentDescription = "I'm working over the app!"
How can I fix the first snippet?
I know this is an old question but just in case anyone faces the same issue:
According to the documentation, You need the native Facebook app to be installed in order to use FBSDKSharePhotoContent and you cannot use FBSDKShareDialog in that case.
A close workaround to achieve almost the same result is using FBSDKShareDialog (which only supports FBSDKShareLinkContent) as follows:
let content: FBSDKShareLinkContent = FBSDKShareLinkContent()
content.imageURL = URL(string: "www.example.com/my_image.jpg")
content.contentURL = URL(string: "www.example.com/target_url")
content.contentTitle = "My Title"
content.contentDescription = "My Description"
let dialog: FBSDKShareDialog = FBSDKShareDialog()
dialog.fromViewController = self
dialog.delegate = self // make sure to conform to FBSDKSharingDelegate protocol
dialog.shareContent = content
if !dialog.canShow() {
// fallback to non-native mode
dialog.mode = .feedBrowser
}
dialog.show()
You can find the protocol's methods here.
It only works when Facebook app is installed. Also, specify mode = .native explicitly.
let content = FBSDKSharePhotoContent()
let photo = FBSDKSharePhoto(image: image, userGenerated: true)
content.photos = [photo].flatMap({ $0 })
let dialog = FBSDKShareDialog()
dialog.fromViewController = viewController
dialog.shareContent = content
dialog.delegate = self
dialog.mode = .native
dialog.show()
If not, it will use SLComposeViewController, and you will get error
SLComposeViewController isAvailableForServiceType got serviceType com.apple.social.facebook isAvailable 0
Good practice is to debug on FBSDKShareDialog.m to see if things don't work for you
- (BOOL)show
{
BOOL didShow = NO;
NSError *error = nil;
if ([self _validateWithError:&error]) {
switch (self.mode) {
case FBSDKShareDialogModeAutomatic:{
didShow = [self _showAutomatic:&error];
break;
}
case FBSDKShareDialogModeBrowser:{
didShow = [self _showBrowser:&error];
break;
}
case FBSDKShareDialogModeFeedBrowser:{
didShow = [self _showFeedBrowser:&error];
break;
}
case FBSDKShareDialogModeFeedWeb:{
didShow = [self _showFeedWeb:&error];
break;
}
case FBSDKShareDialogModeNative:{
didShow = [self _showNativeWithCanShowError:&error validationError:&error];
break;
}
case FBSDKShareDialogModeShareSheet:{
didShow = [self _showShareSheetWithCanShowError:&error validationError:&error];
break;
}
case FBSDKShareDialogModeWeb:{
didShow = [self _showWeb:&error];
break;
}
}
}
if (!didShow) {
[self _invokeDelegateDidFailWithError:error];
} else {
[self _logDialogShow];
[FBSDKInternalUtility registerTransientObject:self];
}
return didShow;
}
Lesson learned:
Be aware of FB changes.
Check for change log every morning
Things that work today may not work tomorrow
I'm trying to post to facebook, which works fine but none of my strings from my content variables are being added to the share dialog.
let content : FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string: "<INSERT STRING HERE>")
content.contentTitle = "My Title Here"
content.contentDescription = "My description here!"
content.imageURL = NSURL(string: "<INSERT STRING HERE>")
let shareDialog = FBSDKShareDialog()
shareDialog.fromViewController = self
shareDialog.shareContent = content
shareDialog.delegate = self
if !shareDialog.canShow() {
print("cannot show native share dialog")
}
shareDialog.show()
Facebook's policies don't allow you to pre-populate status messages and require all content to be user generated. Here is what I have done and I managed to get the URL in the Facebook popup:
let activityItems = ["My app text", "", "http://google.com"]
let vc = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
self.presentViewController(vc, animated: true, completion: nil)
If I open Twitter for example I get "My app text" and the URL, for Facebook I only get the URL.