简体   繁体   English

Facebook共享对话框回调在iOS中无效

[英]Facebook share dialog callback not working in iOS

I'm implementing the share dialog using the Facebook SDK for iOS. 我正在使用Facebook SDK for iOS实现共享对话框。 Everything works fine except for the callback. 除了回调之外,一切正常。 This is the function that displays the dialog: 这是显示对话框的功能:

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];

The view controller implements the FBSDKSharingDelegate and the three required methods: 视图控制器实现FBSDKSharingDelegate和三个必需的方法:

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

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

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

Basically I have to detect if users pressed the cancel button because I give them a reward only if they effectively share the content. 基本上我必须检测用户是否按下了取消按钮,因为我只有在他们有效地共享内容时才给予奖励。 The problem is that even if I press the cancel button the only callback that is invoked is: 问题是,即使我按下取消按钮,唯一被调用的回调是:

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

and not 并不是

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

as expected. 正如所料。 Furthermore using iOS8 the variable results is empty if the cancel button is pressed, otherwise it contains the post_id, but this does not happen with iOS7, where the result is always empty. 此外,使用iOS8,如果按下取消按钮,变量结果为空,否则它包含post_id,但iOS7不会发生这种情况,结果总是为空。

What am I doing wrong? 我究竟做错了什么? What am I supposed to do to have the sharerDidCancel callback working properly? 我应该怎么做才能使sharerDidCancel回调正常工作?

Thanks for any help! 谢谢你的帮助!

Try entering this to your appdelegate. 尝试将此输入到您的appdelegate。 It worked for me to call the right delegate but the result dictionary is still empty and I can't get the post_id. 它适用于我调用正确的委托,但结果字典仍然是空的,我不能得到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];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM