Facebook Share Dialog in iOS

前端 未结 4 1085
粉色の甜心
粉色の甜心 2021-01-14 05:56

I am trying to implement the native Share dialog from Facebook in a sample application.

Seem to have some problem in doing so.

Things I have done so far:

4条回答
  •  萌比男神i
    2021-01-14 06:34

    Do you have Facebook App installed on your device? The Share dialog only works if you have the Facebook app installed.

    From the Share dialog documentation :

    Tip 1: What if people don't have the Facebook app installed?

    The Share dialog can't be displayed if people don't have the Facebook app installed. Apps can detect this by calling [FBDialogs canPresentShareDialogWithParams:nil]; and may disable or hide a sharing button or fall back to the Feed dialog to share on the web. See the HelloFacebookSample included with the iOS SDK for an example.

    From what I saw, iOS 6 will return NO for + canPresentShareDialogWithParams:. It only responds to + canPresentOSIntegratedShareDialogWithSession:. But I could be wrong here.

    Anyways, this is how I do it - 1. For sharing links :

    if ([FBDialogs canPresentShareDialogWithParams:nil]) {
    
        NSURL* url = [NSURL URLWithString:link.url];
        [FBDialogs presentShareDialogWithLink:url
                                  handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
                     if(error) {
                           NSLog(@"Error: %@", error.description);
                     } else {
                           NSLog(@"Success");
                     }
         }];
    }
    

    2.For OpenGraph calls :

    id pictureObject =
        [FBGraphObject openGraphObjectForPostWithType:@"your_namespace:picture"
                                                title:image.title
                                                image:image.thumbnailUrl
                                                  url:image.url
                                          description:@""];
    
        id action = (id)[FBGraphObject graphObject];
        [action setObject:pictureObject forKey:@"picture"];
    
        [FBDialogs presentShareDialogWithOpenGraphAction:action
                                              actionType:@"your_namespace:action_name"
                                     previewPropertyName:@"picture"
                                                 handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
                                                     if(error) {
                                                         NSLog(@"Error: %@", error.description);
                                                     } else {
                                                         NSLog(@"Success");
                                                     }
                                                 }];
    

    Check out other ways to share on iOS here

    Hope this helps.

提交回复
热议问题