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

5

9

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!

Toneme answered 12/5, 2015 at 8:38 Comment(6)
If (NSDictionary *) is not nil then user pressed the post button. Otherwise he/she cancel it.Inductile
possible duplicate of Facebook SDK share always returns sharerDidCancelSelectman
I'm having the same issue, definitely seems like a bug in the SDK.Pastoralize
Did you figure this out? This is absolutely ridiculous that there's no way to tell if the user cancelled. How the hell are we supposed to know whether they shared or not? The hell is wrong with the FB team?Leyva
same here. if anybody got the solution plz shareKestrel
8 years later, we still have this issue. This is crazy that Facebook doesn't care about such crucial aspect of sharing. Makes you wonder what they are doing all day...Abrahamsen
J
3

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()
Jarita answered 26/10, 2017 at 12:18 Comment(1)
But why? The feedWeb dialog looks bad in my appForwent
D
2

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.

Dickey answered 6/5, 2016 at 10:54 Comment(0)
U
0

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.

Unconscionable answered 27/11, 2015 at 2:47 Comment(0)
B
0

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.

Butterfish answered 20/9, 2018 at 6:46 Comment(1)
Doesn't work. !Abrahamsen
C
-1

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")
    }
}
Conjugated answered 6/8, 2015 at 0:8 Comment(3)
postId will not come if you share via native Facebook appAbsinthism
results["postId"] is nil for me even after a successful post. The results dictionary is empty for both cancelled post and successful post..Pastoralize
@Pastoralize i'm having same trouble here. How to know exactly the post has been shared succesfully? sometimes results returns nil, even the post has been posted!Unapt

© 2022 - 2024 — McMap. All rights reserved.