FBDialogs presentShareDialogWithParams回调处理程序永远不会被调用

时间:2014-03-12 21:34:52

标签: ios facebook sdk callback handler

我正在使用FBDialogs在Facebook上分享。

Facebook分享工作正常,但处理程序永远不会被调用(我在第一行放置断点)

我的SDK是通过CocoaPods

安装的
pod 'Facebook-iOS-SDK',         '3.9.0'

这里是代码,几乎是facebook dev页面上的示例。我正在使用ios7在iPod上进行测试。

// If the Facebook app is installed and we can present the share dialog
if ([FBDialogs canPresentShareDialogWithParams:params]) {
    // Present the share dialog

    [FBDialogs presentShareDialogWithParams:params
                              clientState:nil
                                    handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
                                        //never gets here
                                        if(error) {
                                            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                                            message:[NSString stringWithFormat: @"O comparilhando não foi bem sucedido. %@",error.description]
                                                                                           delegate:nil
                                                                                  cancelButtonTitle:@"OK"
                                                                                  otherButtonTitles:nil];
                                            [alert show];

                                        } else {
                                            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Sucesso"
                                                                                            message:@"O compartilhando foi bem sucedido"
                                                                                           delegate:nil
                                                                                  cancelButtonTitle:@"OK"
                                                                                  otherButtonTitles:nil];
                                            [alert show];

                                        }}];

我的老板最终弄明白了。 我在AppDelegate中错过了这个方法。没有它,Facebook无法将数据传回我的应用程序

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:        (NSString *)sourceApplication annotation:(id)annotation {

BOOL urlWasHandled = [FBAppCall handleOpenURL:url
                            sourceApplication:sourceApplication
                              fallbackHandler:^(FBAppCall *call) {
                                  // incoming link processing goes here
                                }];

    return urlWasHandled;
}

1 个答案:

答案 0 :(得分:0)

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation {


    if ([[[[NSString stringWithFormat:@"%@",url] componentsSeparatedByString:@":"] objectAtIndex:0]isEqualToString:@"your FB ID"]) {

        return [FBSession.activeSession handleOpenURL:url];

    }

可能会帮助你。