【发布时间】:2015-09-28 15:05:24
【问题描述】:
在我的 iOS 应用中,我有一个 Facebook 分享按钮,它会打开一个 FBSDKShareDialog:
-(IBAction)post:(id)sender{
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
content.contentURL = [NSURL URLWithString:self.setShareURL];
NSLog(@"facebook share url: %@", self.setShareURL);
content.contentTitle= [NSString stringWithFormat: @"%@'s set", self.username];
content.contentDescription=@"#spinturntable";
FBSDKShareDialog *fbdialog = [[FBSDKShareDialog alloc] init];
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fbauth2://"]]){
fbdialog.mode = FBSDKShareDialogModeNative;
}
else {
fbdialog.mode = FBSDKShareDialogModeBrowser; //or FBSDKShareDialogModeAutomatic
}
fbdialog.shareContent = content;
fbdialog.delegate = self;
fbdialog.fromViewController = self;
[fbdialog show];
}
如果用户没有 Facebook 应用程序,它会在 Safari 中打开一个窗口,要求他们登录 Facebook。
如果用户在没有登录的情况下返回我的应用程序,则调用 FBSDKSharing didCompleteWithResults 回调,但不返回任何结果:
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
NSLog(@"results: %@", results);
NSLog(@"posted to facebook successfully!");
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];
});
}
但是,如果用户登录并完成 Facebook 上的帖子,回调也会被触发,但没有结果。
如何区分以便仅在用户实际发布到 Facebook 时才显示已发布提醒?
【问题讨论】:
标签: ios facebook facebook-graph-api