Facebook SDK Share Image with Text - ios

Prior to using Facebook SDK we used to share via UIActivityViewController since Facebook does not allow for us to pre-fill information on the user sharing, our solution was to use information the user description of the Image being share UIPasteboard.general.string. So the app would switch to the messenger and the user could paste. This worked just fine until we started using the Facebook SDK.
Now it seems that the UIPasteboard.general.string is reset when it opens up messenger and we no longer can get the image description copied to the clipboard.
This is how I'm sharing to messenger:
let sharePhoto = FBSDKSharePhoto()
sharePhoto.image = image
let content = FBSDKSharePhotoContent()
content.photos = [sharePhoto]
FBSDKMessageDialog.show(with: content, delegate: delegate)

Yes, I'm stacked on that staff too after FB lib update. As for me - I figured out with web link on image like it shown below. As a result - you do not need ask user to paste something. You can do it by yourself and paste it to title or description.
let content = LinkShareContent(url: url,
title: title,
description: description,
quote: nil,
imageURL: imageURL)
let dialog = ShareDialog(content: content)
dialog.presentingViewController = parentVC
dialog.mode = .automatic
dialog.completion = { result in
...
}
try? dialog.show()

Facebook is not support UI share both image and text. If you want to share an image and a text together, you can create a custom story from your app's settings, and share it as an open graph story. Here's the documentation.

Related

How to use Branch.io to create a referral program for iOS app?

I have not been able to find a complete guide to creating a useful referral program in the Branch.io documentation. At the moment, I have the iOS SDK integrated as well as the dashboard setup correctly. I am using BranchUniversalObject and BranchLinkProperties and then showing the share sheet when a user attempts to share their referral yet when I click on the shared link, there is no reference to the user who referred the new user. I am setting a custom parameter referringUserID but that doesn't seem to get passed into the deep link when the user launches the app after download. I am also setting the canonicalIdentifier for the BranchUniversalObject. Is it better to generate a unique URL upon user account creation then use that from the share sheet and compare the +non_branch_link upon user launch? The code below is what I have for the current implementation of how we display the share sheet. What is the proper way to share links on iOS to track actual referrals?
let branchUniversalObject = BranchUniversalObject(canonicalIdentifier: Session.shared.userId!)
branchUniversalObject.title = "My Share Link"
branchUniversalObject.contentDescription = "Share"
// Feature (utm_medium) = marketing, referrals
// Channel (utm_source) = sticker, referral link, etc
// Campaign (itm_campaign) = launch, holiday season, etc.
// Tags = June Offer, Summer, Launch Promo
let branchLinkProperties = BranchLinkProperties()
branchLinkProperties.campaign = "Referral"
//branchLinkProperties.channel = "Referral Link"
branchLinkProperties.feature = "referrals"
branchLinkProperties.addControlParam("referringUserID", withValue: Session.shared.userId!)
branchUniversalObject.showShareSheet(
with: branchLinkProperties,
andShareText: "",
from: viewController,
completion: nil)

Choose what share actions get what content with UIActivityViewController

I am currently using UIActivityViewController to share an url to other apps. This part works fine.
But when I'm sharing to an app like iMessage, Whatsapp or Mail. I would like to add a string.
Example:
Sharing -> airdrop: https://www.google.com
Sharing -> iMessage: "Hi there, checkout this cool website: https://www.google.com"
I tried to do it by adding both an Url object and a String into the UIActivityViewController like so:
let url = URL(string: "https://www.google.com)
let text = "Hi there, checkout this cool website: \(url)"
let items: [Any] = [url, text]
let controller = UIActivityViewController(
activityItems: items,
applicationActivities: nil)
DispatchQueue.main.async{self.present(controller, animated: true, completion: nil)}
^not the actual code, but enough to draw a picture
This does work with Airdrop, it opens the url.
It also works in Mail, it uses the string containing the url.
It doesn't work however in iMessage. iMessage takes both and combines them like so:
https://www.google.com Hi there, checkout this cool website: https://www.google.com
Does anyone have any suggestions for me to keep the functionality for Airdrop/Mail etc. But for it to also work on iMessage?
Use a UIActivityItemSource. The UIActivityItemSource is told the identifier of the requesting process, so you can refrain from handing the URL to Messages and hand it just the string, which is sufficient.

iOS - Firebase dynamic linking with Facebook friends invite issue

I am using firebase dynamic linking to send app invitation using email and sms gateway.
Basically, I am sending the invite code in deep link.
User who's installs with that invite code is connected to my user circle.
Now, I want to send invite code to my Facebook friends. Is there a way to send deep link through Facebook invite.
Following is the code to send the Facebook app invite:
#IBAction func showFacebookInvite(_ sender: AnyObject) {
let content = FBSDKAppInviteContent()
content.appLinkURL = URL(string: "https://fb.meXXXXX")
let obj = FBSDKAppInviteDialog()
obj.content = content
obj.delegate = self
let temp = FBSDKAppInviteDialog.validate(obj)
print(temp)
content.destination = .facebook
FBSDKAppInviteDialog
.show(from: self, with: content, delegate: self)
}
Any suggestions.
You can assign Firebase Dynamic Link to content.appLinkURL . When Facebook friend accepts the invite, friend will navigate to the link and install the App.
This should function identical to email/sms gateway.
To create short FDL links use iOS Builder API https://firebase.google.com/docs/dynamic-links/ios/create

while sharing content on facebook it looks different after sharing than content shared from php

I am using FBSDKShareDialog to share content from my iOS App but it doesn't attractive like content shared with PHP side.
Below is my code for FBSDKShareDialog to share content over facebook.
let shareLinkContent:FBSDKShareLinkContent = FBSDKShareLinkContent()
shareLinkContent.contentURL = NSURL(string: "http://www.google.com")
shareLinkContent.imageURL = strImageUrl
shareLinkContent.contentTitle = strName
shareLinkContent.contentDescription = "Ik heb ‘\(strName)’ beoordeeld en gaf deze whisky '\(strPercentage)' punten"
FBSDKShareDialog.showFromViewController(self, withContent: shareLinkContent, delegate: self)
Check image below to see difference between content shared using my iOS App and PHP site.
1. Post from iOS App.
1. Post from PHP Site.
Please tell me solution for this so I can post content to Facebook like PHP site.
I just want to share content like Second Image i.e content shared from PHP site.

IOS Facebook SDK : what wrong with sharerDidCancel:(id<FBSDKSharing>)sharer delegate?

I use facebook sdk worked well except for delegate "sharerDidCancel:(id)sharer".
When i cancel my share with native dialog FB app, the delegate "sharer:(id)sharer didCompleteWithResults:(NSDictionary *)results" always called ? So i can't handle my users when they post or cancel the dialog share, is this a bug of Facebook SDK for IOS ?
Thanks for any helping!
I faced same issue during sharing in iOS 11. I have just changed native FB dialog to web dialog. As below:
Use below method:
dialog.mode = FBSDKShareDialogMode.feedWeb
instead of
dialog.mode = FBSDKShareDialogMode.native
Below is my code.It's work fine for me.
let content: FBSDKShareLinkContent = FBSDKShareLinkContent()
content.quote = "My Text"
content.contentURL = NSURL(string: String(format:"My Url"))! as URL!
let dialog: FBSDKShareDialog = FBSDKShareDialog()
dialog.fromViewController = self
dialog.shareContent = content
dialog.delegate = self
dialog.mode = FBSDKShareDialogMode.feedWeb
dialog.show()
I've just been digging through the Facebook SDK docs and found this:
sharer:didCompleteWithResults: when the user successfully shares. Furthermore there will also be a postId key in the results dictionary if the user gave the app publish_actions permissions. If that user has not logged in with Facebook Login, this method will also be called if the user clicks on Cancel.
So, unless you're logged in, checking cancel won't work (which is rubbish). Looks like you might be able to give some permissions and then check the postId though.
I found it is useful when you use FBSDKShareDialogModeWeb to share a link and FBSDKShareDialogModeNative to share a photo, then when you click cancel button, it will return to canceled delegate. But it only worked before iOS 9.1, and not support on iOS 9.1. I don't know why and how to solve it yet. Hope this answer is helpful.
I found a solution for this issue. Please match facebookdiplayname name in xcode plist and facebook developer account. If facebookdiplayname same then facebook delegate methods working right way.
I also have found that sharerDidCancel is never called when canceling.
You can do like Tejvansh suggested but checking if results is nil won't work because it's not nil when the user cancels, just empty.
The way I'm doing it is to check if the key "postId" exists, in which case the post was successful otherwise I assume the user canceled.
Swift example:
func sharer(sharer: FBSDKSharing!, didCompleteWithResults results: [NSObject : AnyObject]!) {
println("sharing results \(results)")
if results["postId"] != nil {
println("shared")
} else {
println("canceled")
}
}

Resources