2

I use a UIButton to share using Facebook's SDK 4.31.1. Once tapped, a share dialog is presented.

- (IBAction)btnSharePressed:(id)sender
{
    [self displayShareDialog];
}

- (void)displayShareDialog {
    FBSDKShareLinkContent *content = [self getShareContent];

    if ([FacebookHandler isFacebookAppInstalled]) {
        [FBSDKShareDialog showFromViewController:self
                                     withContent:content
                                        delegate:self];
    } else {
        FBSDKShareDialog * shareDialog = [[FBSDKShareDialog alloc] init];
        [shareDialog setMode:FBSDKShareDialogModeBrowser];
        [shareDialog setDelegate:self];
        [shareDialog setFromViewController:self];
        [shareDialog setShareContent:content];
        [shareDialog show];
    }
}

// Expects the URL of the scheme e.g. "fb://"
+ (BOOL)isFacebookAppInstalled {
    NSArray* fbSchemes = @[@"fbapi://",
                           @"fb-messenger-api://",
                           @"fbauth2://",
                           @"fbshareextension://"];
    BOOL isInstalled = false;

    for (NSString* fbScheme in fbSchemes) {
        isInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:fbScheme]];
        if(isInstalled) {
            break;
        }
    }
    return isInstalled;
}

But when Facebook app is not installed, on every launch, on the first successful share the delegate method sharerDidCancel: is called and on any further successful share the correct delegate method sharer:didCompleteWithResults: is called. I have correctly set the FacebookDisplayName and FacebookId in the plist file so it’s not about that. I also tried switching FBSDKShareDialogModeBrowser with FBSDKShareDialogModeFeedBrowser with no luck.

Can someone shed some light on why the cancel method is called first, even though the share was completed successfully and why it is like that only after the first share?

iPeter
  • 1,330
  • 10
  • 26
Got99Errors
  • 328
  • 3
  • 11

0 Answers0