Facebook SDK共享始终返回sharerDidCancel

时间:2015-07-07 21:05:14

标签: ios facebook cocoa-touch facebook-ios-sdk

我正在尝试与Facebook SDK分享帖子,但是如果我分享或取消帖子,总是会调用sharerDidCancel。 这是我的代码

- (void)shareFacebook {
    FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
    content.contentURL = [NSURL URLWithString:@"http://www.google.com"];
    [FBSDKShareDialog showFromViewController:view
                                 withContent:content
                                    delegate:self];
}

- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults :(NSDictionary*)results {
    NSLog(@"FB: SHARE RESULTS=%@\n",[results debugDescription]);
}

- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error {
    NSLog(@"FB: ERROR=%@\n",[error debugDescription]);
}

- (void)sharerDidCancel:(id<FBSDKSharing>)sharer {
    NSLog(@"FB: CANCELED SHARER=%@\n",[sharer debugDescription]);
}

这个类实现了FBSDKSharingDelegate,在我的Info.plist中我已经输入了FacebookAppID和FacebookDisplayName。

在我的AppDelegate中,我有这个方法:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
    return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
}

我做错了什么?我完全按照Facebook SDK指南。

由于

1 个答案:

答案 0 :(得分:2)

Solved, my error was in the AppDelegate method:

here is a link with the solution http://jitu1990.blogspot.it/2015/05/share-with-facebook-from-ios-app.html

And here is the code

- (BOOL)application:(UIApplication *)application openURL:(NSURL* )url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {   
    return [[FBSDKApplicationDelegate sharedInstance] application:application
                                                      openURL:url sourceApplication:sourceApplication annotation:annotation];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    [FBSDKAppEvents activateApp];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    return [ [FBSDKApplicationDelegate sharedInstance] application :application
             didFinishLaunchingWithOptions:launchOptions]
  }