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")
}
}
Related
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.
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
I am using the alloy framework with appcelerator titanium and have done like this:
alloy.js
Alloy.Globals.Facebook = require('facebook');
Alloy.Globals.Facebook.permissions = ['public_profile'];
index.js
Alloy.Globals.Facebook.addEventListener('login', function(e) {
if (e.success) {
Ti.API.info("VALID FACEBOOK LOGIN");
var token = Alloy.Globals.Facebook.accessToken;
Ti.API.info("*** fb accessToken: "+token);
}
else{
Ti.API.info("FAILED FACEBOOK LOGIN...");
}
});
index.xml
<LoginButton id="fbButton" module="facebook" />
When i try to login using the button, the login is okay, and the facebook button changes to "logout" instead. However, no login event is ever fired and the evenlistener in index.js never gets anything.
What is causing this? Should i add the event lister in some other way?
iOS on device 9.3.1
Titanium SDK 5.2.2.GA
As pointed out in an earlier comment to the question the module was not initialized. Adding the initialize() line into my alloy.js seems to fix the problem, now i receive the login events.
in alloy.js
Alloy.Globals.Facebook = require('facebook');
Alloy.Globals.Facebook.permissions = ['public_profile'];
Alloy.Globals.Facebook.initialize();
i think you forget to add this instruction :
Alloy.Globals.Facebook.authorize();
As an ugly workaround until events gets fixed i simply added a setInterval that polls if Alloy.Globals.Facebook.loggedIn is true or not and then do the appropriate codes that should have been inside the event handler...
After submitting the app to app store, for some reason the reviewers could not get any events... this is really bad. It works in my simulators and on my device, but not for the submitted app when they test it...
No idea what to do really...
I am trying to implement Open Graph Stories in iOS of facebook as shown in here: https://developers.facebook.com/docs/sharing/opengraph/ios#custom
I need to post it to facebook via custom interface, not with facebook share dialog.
So far, I can successfully create an open graph object per request, it does not return any error but does not post it to Facebook timeline neither. All I see in xcode is: postId: 113077439054125, completionGesture: post
I am not sure what goes wrong.
Here is my code snippet:
var photo = FBSDKSharePhoto(imageURL: imgUrl, userGenerated: false)
var properties : [NSObject : AnyObject] = [
"og:type" : "video.movie",
"og:title" : "TEST TITLE",
"og:image" : "https://www.facebook.com/images/fb_icon_325x325.png",
"fb:explicitly_shared" : true]
var object = FBSDKShareOpenGraphObject(properties: properties)
var shareApi = FBSDKShareAPI()
var action = FBSDKShareOpenGraphAction(type: "MYNAMESPACE:myAction", object: object, key: "movie")
var content = FBSDKShareOpenGraphContent()
content.action = action
content.previewPropertyName = "movie"
shareApi.delegate = self
shareApi.shareContent = content
shareApi.share()
I've been struggling with it for some time by now. Any help would be appreciated.
Thanks.
You should have solved it. If not, did you get the token for publish_actions permission?
This is how you can get it:
Go to Graph API Explorer.
Select your application.
Click "Get User Access Token".
Select "Extended Permissions" then "publish_actions".
Click "Get Access Token".
That's it.
You have to get your app approved by Facebook in order to gain publish_actions right? When you login to Facebook what are the different access permissions that it shows. Usually you will get a line in the Facebook permission page that says this app does not let you post to timeline or something like that.
What you can try is to create Test Users and use it to login. Test users get all the permissions that you ask for since they are separate from normal users. Note that these are not same as Testers which are still normal FB accounts.
Try using Test Users and once your app is ready to go live, send it to Facebook from the app dashboard and once approved by them you should be good to go live.
I have a sharekit implementation where everything works fine, but if there is no account set for facebook, upon pressing the settings button, the actionsheet is just dismissed and the user is returned to the app, not to the settings page in system prefs.
How do I get the settings button to send the user to the settings page?
the code i use to init the action sheet:
NSURL *url = [NSURL URLWithString:#"http://test"];
SHKItem *item = [SHKItem URL:url title:#"test"];
SHKActionSheet *actionSheet = [SHKActionSheet actionSheetForItem:item];
// Display the action sheet
[actionSheet showFromTabBar:self.tabBarController.tabBar];
This is a known, unresolved issue with ShareKit. You could submit a pull request to fix it, or work around it by checking SLComposeViewController:
if([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook]) {
// show ShareKit
} else {
// tell them to get Facebook
}
before displaying ShareKit. Of course, that would make it so users without Facebook (like Twitter-only folks) couldn't use ShareKit. On the other hand, you could switch over to Apple's Share Sheets, or write your own, but those also have their disadvantages. Kind of a catch-22.