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

Jur*_*rik 8 sdk facebook callback handler ios

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

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

我的SDK是通过CocoaPods安装的

pod 'Facebook-iOS-SDK',         '3.9.0'
Run Code Online (Sandbox Code Playgroud)

这是代码,几乎是facebook开发页面上的例子.我正在使用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];

                                        }}];
Run Code Online (Sandbox Code Playgroud)

解决方案:

我的老板最终弄明白了.我在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;
}
Run Code Online (Sandbox Code Playgroud)

Dax*_*gar 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];

    }
Run Code Online (Sandbox Code Playgroud)

也许这对你有帮助。