This question already has answers here:
FBSDKShareDialog cancels when it should post

(4个答案)


5年前关闭。




我正在尝试与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指南。

谢谢

最佳答案

解决了,我的错误出在AppDelegate方法中:

这是解决方案http://jitu1990.blogspot.it/2015/05/share-with-facebook-from-ios-app.html的链接

这是代码

- (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]
  }

关于ios - Facebook SDK共享始终返回sharerDidCancel ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31279243/

10-08 20:35