iOS的FBSDKShareDialog回调函数

5

当用户完成创建帖子后,FBSDKShareDialog返回到您的应用程序时,回调方法是什么?

这是我用来创建对话框的代码:

-(IBAction)post:(id)sender{
    FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
    content.contentURL = [NSURL URLWithString:self.spinShareURL];
    content.contentDescription=@"#spin";
    self.fromFacebook = true;

    [FBSDKShareDialog showFromViewController:self withContent:content delegate:nil];

}

我看到有人提到了回调函数。

-(void)dialogDidComplete:(FBSDKShareDialog *)dialog{
 }

但是这对我没有用。

委托应该在 FBSDKSharingDelegate 上完成,而不是在 FBSDKShareDialog 上完成,您可以在此处放置 nil:https://developers.facebook.com/docs/reference/ios/current/protocol/FBSDKSharingDelegate/ - Larme
1个回答

14

我在以下页面找到了解决方案:

http://jitu1990.blogspot.com/2015/05/share-with-facebook-from-ios-app.html

这是我的最终代码:

-(IBAction)post:(id)sender{
    FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
    content.contentURL = [NSURL URLWithString:self.spinShareURL];
    content.contentTitle= [NSString stringWithFormat: @"%@'s spin", self.username];
    content.contentDescription=@"#spin";
    self.fromFacebook = true;

    [FBSDKShareDialog showFromViewController:self withContent:content delegate:self];

}- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
    NSLog(@"returned back to app from facebook post");
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
                                                    message:@"Posted!"
                                                   delegate:self
                                          cancelButtonTitle:nil
                                          otherButtonTitles:nil];
    [alert show];
    double delayInSeconds = 1.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [alert dismissWithClickedButtonIndex:0 animated:YES];
    });
}

- (void)sharerDidCancel:(id<FBSDKSharing>)sharer
{
   NSLog(@"canceled!");
}

- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
    NSLog(@"sharing error:%@", error);
    NSString *message = @"There was a problem sharing. Please try again!";
    [[[UIAlertView alloc] initWithTitle:nil message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}

我正在使用这些委托函数,在成功分享后它会进入sharerDidCancel,@scientiffic能指导我吗? - abdulrauf618

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接