Gusutafu
Gusutafu

Reputation: 755

Facebook SDK: Knowing if sharing took place

I am sharing a link from my app using code from HelloFacebookSample, but I can't figure out how to know if sharing actually took place. I use this for sharing:

FBAppCall *appCall = [FBDialogs presentShareDialogWithLink:urlToShare
                                                      name:@"Hello Facebook"
                                                   caption:nil
                                               description:@"The 'Hello Facebook' sample application showcases simple Facebook integration."
                                                   picture:nil
                                               clientState:nil
                                                   handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
                                                       if (error) {
                                                           NSLog(@"Error: %@", error.description);
                                                       } else {
                                                           NSLog(@"Success!");
                                                       }
                                                       NSLog(@"Results: %@",results);
                                                   }];

and that works fine. The problem is accessing the results dictionary. I figured out that I need to add this to the app delegate:

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {
  // attempt to extract a token from the url
  return [FBAppCall handleOpenURL:url
                sourceApplication:sourceApplication
                  fallbackHandler:^(FBAppCall *call) {
                    NSLog(@"In fallback handler");
                  }];
}

Otherwise the handler isn't run at all. The weird thing now is that in the sample app the results dictionary has two fields,

completionGesture = cancel;
didComplete = 1;

but when I use the exact same code in my own app, on the same phone, the dictionary only contains

didComplete = 1;

Why is that, and is there some other way to find out if the user shared or cancelled?

Upvotes: 3

Views: 1590

Answers (1)

Ming Li
Ming Li

Reputation: 15662

See this section here on what you can expect in the result dictionary, and why only some values are available:

https://developers.facebook.com/ios/share-dialog/#handling-responses

Upvotes: 1

Related Questions