iOS 的 FBSDKShareDialog 回调
Posted
技术标签:
【中文标题】iOS 的 FBSDKShareDialog 回调【英文标题】:FBSDKShareDialog callback for iOS 【发布时间】:2015-06-04 22:39:18 【问题描述】: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
放在哪里:developers.facebook.com/docs/reference/ios/current/protocol/…
【参考方案1】:
我在以下页面找到了解决方案:
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你可以指导我以上是关于iOS 的 FBSDKShareDialog 回调的主要内容,如果未能解决你的问题,请参考以下文章
iOS Facebook SDK 4 FBSDKShareDialog
FSSDKShareKit - 初始化 iOS 上的 FBSDKShareDialog 崩溃
适用于iOS的Facebook SDK:未显示FBSDKShareDialog
iOS:FBSDKShareDialog 打开应用但不允许用户分享链接
如何在不使用原生 ios 应用程序中的 FBSDKShareDialog 的情况下在 Facebook 墙上分享照片或链接