Facebook iOS SDK 4.1.0 Share Callback

前端 未结 1 425
半阙折子戏
半阙折子戏 2021-01-21 19:09

Using the FBSDK mentioned in the title of this question, I present a simple share dialog in a view controller:

// Setup the content for the share
FBSDKShareLinkC         


        
相关标签:
1条回答
  • 2021-01-21 19:31

    Edit: It turns out, the results dictionary is empty when the completion method is called if the Facebook app is installed on the device. To overcome this, a check needs to be done to see if Facebook is installed first.

    Of course after posting I stumbled upon the answer. The results dictionary returned in the didCompleteWithResults method contains a postId key if the share actually occurred. So the logic is as simple as:

    - (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
    {
        NSURL *fbURL = [NSURL URLWithString:@"fb://"];
        if (![[UIApplication sharedApplication] canOpenURL:fbURL])
            if (results[@"postId"]) {
                NSLog(@"Sweet, they shared, and Facebook isn't installed.");
            } else {
                NSLog(@"The post didn't complete, they probably switched back to the app");
            }
        } else {
            NSLog(@"Sweet, they shared, and Facebook is installed.");
        }
    }
    

    Although this works, it doesn't seem to be a very safe way of going about things (what if Facebook changes the key from "postId" to something else in the future? Unlikely but you get my point).

    0 讨论(0)
提交回复
热议问题