iOS的FBSDKShareDialog回调 [英] FBSDKShareDialog callback for iOS

查看:156
本文介绍了iOS的FBSDKShareDialog回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



这是我必须创建的对话框:

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

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

}

我读到某个地方有一个回调

   - (void)dialogDidComplete:(FBSDKShareDialog *)对话框{
}
pre>

但这对我来说无效。

解决方案

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



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 *)结果
{
NSLog(@从facebook post返回到应用程序 );
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:nil
message:@发贴!
委托: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(@cancelled!


- (void)sharer:(id< FBSDKSharing>)sharer didFailWithError :( NSError *)错误
{
NSLog(@共享错误:% @,错误);
NSString * message = @共享问题,请再试一次!
[[[UIAlertView alloc] initWithTitle:nil message:message delegate:nil cancelButtonTitle:@OKotherButtonTitles:nil] show];
}


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.

解决方案

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

这篇关于iOS的FBSDKShareDialog回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆