在我的应用程序中使用 FBSDKLoginKit、FBSDKShareKit 登录、共享链接和点赞链接时,我收到此错误。
我使用 FBSDKLoginButton 登录
@property (nonatomic, strong) IBOutlet FBSDKLoginButton *loginButton;
- (void)viewDidLoad {
[super viewDidLoad];
self.loginButton.publishPermissions = @[@"publish_actions"];
}
使用FBSDKShareKit进行分享:
- (FBSDKShareDialog *)getShareDialogWithContentURL:(FBSDKShareLinkContent *)content
{
FBSDKShareDialog *shareDialog = [[FBSDKShareDialog alloc] init];
shareDialog.shareContent = content;
return shareDialog;
}
- (IBAction)ShareAppOnFB:(UIButton *)sender {
FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
FBSDKShareDialog *facebookShareDialog = [self getShareDialogWithContentURL:content];
if ([facebookShareDialog canShow]) {
[FBSDKShareDialog showFromViewController:self.parentViewController
withContent:content
delegate:self];
}
}
使用 FBSDKShareKit 点赞:
FBSDKLikeButton *like = [[FBSDKLikeButton alloc] init];
like.objectID = @"";
like.frame = CGRectOffset(like.frame, 50, 100);
[self.view addSubview:like];
在 iOS 9 和 iOS 8 上一切正常,但是当我升级到 Xcode 8 并在 iOS 10 上运行时,当点击“登录”、“分享”和“点赞”按钮时,我会立即看到一个空白页面,之后就没有任何反应。我尝试升级到 Facebook SDK 4.15.1,但没有更好,这个错误仍然发生。有人知道如何修复 iOS 10 上的这个错误吗?
FB SDK 使用 SFSafariViewController,显然在 iOS 10 中它只能从根视图控制器呈现。
解决方案是创建一个新的 UIWindow 实例,添加一个普通的 UIViewController 作为根视图控制器,并使用这个新的 UIViewController 调用 FB SDK:
UIViewController* socialVC = [[UIViewController alloc] init];
// window instance needs to be retained
self.socialWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.socialWindow.rootViewController = socialVC;
// show new window in top of every other UIs
self.socialWindow.windowLevel = UIWindowLevelStatusBar + 10;
[self.socialWindow makeKeyAndVisible];
// show FB Share Dialog
[FBSDKShareDialog showFromViewController:socialVC withContent:content delegate:self];
调用 FB SDK 的 delegate 时不要忘记隐藏窗口:
self.socialWindow.hidden = YES;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)