Facebook共享对话框回调在iOS

时间:2015-07-09 10:02:26

标签: ios facebook sdk share

我正在使用Facebook SDK for iOS实现共享对话框。 除了回调之外,一切正常。 这是显示对话框的功能:

FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
    content.contentURL = <my content url>;
    content.contentTitle = <my title>;
    content.contentDescription = my description;
    content.imageURL = <my image url>;
    [FBSDKShareDialog showFromViewController:self
                                 withContent:content
                                    delegate:self];

视图控制器实现FBSDKSharingDelegate和三个必需的方法:

- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results;

- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error;

- (void)sharerDidCancel:(id<FBSDKSharing>)sharer;

基本上我必须检测用户是否按下了取消按钮,因为只有当他们有效地共享内容时我才会给予奖励。 问题是即使我按下取消按钮,唯一被调用的回调是:

- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results;

而不是

- (void)sharerDidCancel:(id<FBSDKSharing>)sharer;

正如所料。此外,使用iOS8,如果按下取消按钮,变量结果为空,否则它包含post_id,但iOS7不会发生这种情况,结果总是为空。

我做错了什么?我应该做些什么来让 sharerDidCancel 回调正常工作?

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

尝试将此输入到您的appdelegate。我可以调用正确的代理,但结果字典仍然是空的,我无法获得post_id。

#import <FBSDKCoreKit/FBSDKCoreKit.h>

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

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

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