我使用UIButton与Facebook的SDK 4.31.1共享。点击后,会显示一个共享对话框。
- (IBAction)btnSharePressed:(id)sender
{
[self displayShareDialog];
}
- (void)displayShareDialog {
FBSDKShareLinkContent *content = [self getShareContent];
if ([FacebookHandler isFacebookAppInstalled]) {
[FBSDKShareDialog showFromViewController:self
withContent:content
delegate:self];
} else {
FBSDKShareDialog * shareDialog = [[FBSDKShareDialog alloc] init];
[shareDialog setMode:FBSDKShareDialogModeBrowser];
[shareDialog setDelegate:self];
[shareDialog setFromViewController:self];
[shareDialog setShareContent:content];
[shareDialog show];
}
}
// Expects the URL of the scheme e.g. "fb://"
+ (BOOL)isFacebookAppInstalled {
NSArray* fbSchemes = @[@"fbapi://",
@"fb-messenger-api://",
@"fbauth2://",
@"fbshareextension://"];
BOOL isInstalled = false;
for (NSString* fbScheme in fbSchemes) {
isInstalled = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:fbScheme]];
if(isInstalled) {
break;
}
}
return isInstalled;
}
但是当没有安装Facebook应用程序时,在每次启动时,在第一次成功共享时调用委托方法sharerDidCancel:
,并且在任何进一步成功的共享上调用正确的委托方法sharer:didCompleteWithResults:
。
我已在FacebookDisplayName
文件中正确设置FacebookId
和plist
,因此不是这样。
我还尝试用FBSDKShareDialogModeBrowser
切换FBSDKShareDialogModeFeedBrowser
但没有运气。
有人可以解释为什么首先调用cancel
方法,即使共享已成功完成,为什么只有在第一次共享后呢?