iOS 7 - Facebook:检查分享结果

时间:2014-04-22 18:24:54

标签: ios objective-c facebook facebook-sdk-3.1

您是否曾经需要检查Facebook墙上的分享是否成功完成?

我想知道用户是否从SDK的界面取消了共享操作,或者是否由于技术问题而未发布。

我正在使用框架的FBDialogs" FacebookSDK / FacebookSDK.h"在iOS 7上。

永远不会调用像presentShareDialogWithPhotoParams这样的方法的处理程序块。

提前致谢。 侨

1 个答案:

答案 0 :(得分:1)

当您显示订阅源对话框时,您可以使用以下代码来检测用户何时成功共享帖子,用户取消操作或发生错误时:

[FBWebDialogs presentFeedDialogModallyWithSession:nil
                                       parameters:params
                                          handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                                              if (error) {
                                                  // An error occurred, we need to handle the error
                                                  // See: https://developers.facebook.com/docs/ios/errors
                                                  NSLog(@"%@", [NSString stringWithFormat:@"Error publishing story: %@", error.description]);
                                              } else {
                                                  if (result == FBWebDialogResultDialogNotCompleted) {
                                                      // User cancelled.
                                                      NSLog(@"User cancelled.");
                                                  } else {
                                                      // Handle the publish feed callback
                                                      NSDictionary *urlParams = [self parseURLParams:[resultURL query]];

                                                      if (![urlParams valueForKey:@"post_id"]) {
                                                          // User cancelled.
                                                          NSLog(@"User cancelled.");

                                                      } else {
                                                          // User clicked the Share button
                                                          NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
                                                          NSLog(@"result %@", result);
                                                      }
                                                  }
                                              }
                                          }];

当您呈现共享对话框时,您可以让以下来自服务器的错误在邮件成功共享时处理:

[FBDialogs presentShareDialogWithLink:params.link
                                     name:params.name
                                  caption:params.caption
                              description:params.description
                                  picture:params.picture
                              clientState:nil
                                  handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
                                      if(error) {
                                          // An error occurred, we need to handle the error
                                          // See: https://developers.facebook.com/docs/ios/errors
                                          NSLog(@"%@", [NSString stringWithFormat:@"Error publishing story: %@", error.description]);
                                      } else {
                                          // Success
                                          NSLog(@"result %@", results);
                                      }
                                  }];