FBSDKShareDialog callback for iOS

我的梦境 提交于 2019-12-21 16:51:24

问题


What is the callback method for FBSDKShareDialog when it returns back to your app (after the user has finished creating a post)?

This is what I have to create the dialog:

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

}

I read somewhere that there is a callback

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

But this didn't work for me.


回答1:


I found the solution at the following page:

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

Here is my final code:

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


来源:https://stackoverflow.com/questions/30655414/fbsdksharedialog-callback-for-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!