登录并与iOS 10上使用Facebook SDK 4.15.1的Facebook SDK共享和共享时获得空白页 [英] Get blank page while log in, share and like with Facebook SDK on iOS 10 with Facebook SDK 4.15.1

查看:85
本文介绍了登录并与iOS 10上使用Facebook SDK 4.15.1的Facebook SDK共享和共享时获得空白页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用FBSDKLoginKit,FBSDKShareKit登录,共享链接并像我的应用程序中的链接时,出现此错误. 我使用FBSDKLoginButton登录

I get this error when using FBSDKLoginKit, FBSDKShareKit, to login, share link and like a link in my application. I using FBSDKLoginButton to login

 @property (nonatomic, strong) IBOutlet FBSDKLoginButton *loginButton;

- (void)viewDidLoad {
    [super viewDidLoad];

    self.loginButton.publishPermissions = @[@"publish_actions"];
}

使用FBSDKShareKit进行共享:

Using FBSDKShareKit to share:

- (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喜欢:

Using FBSDKShareKit to Like:

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上修复此错误?

Everything work fine on iOS 9 and iOS 8, but when I upgrade into Xcode 8 and run on iOS 10, I get a blank page right away when tap on Login, Share and Like Button, and nothing happens after that. I tried to upgrade to Facebook SDK 4.15.1 but nothing better, this bug still happens. Anyone know how to fix this bug on iOS 10?

推荐答案

FB SDK使用SFSafariViewController,显然在iOS 10中,它只能从根视图控制器中呈现. 解决方案是创建一个新的UIWindow实例,添加一个普通的UIViewController作为根视图控制器,并使用此新的UIViewController调用FB SDK:

FB SDK uses SFSafariViewController, and apparently in iOS 10 it can be presented only from root view controllers. The solution is to create a new UIWindow instance, add a plain UIViewController as root view controller, and call FB SDK with this new UIViewController:

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的委托时,不要忘记隐藏窗口:

Do not forget to hide the window when FB SDK's delegate is called:

self.socialWindow.hidden = YES;

这篇关于登录并与iOS 10上使用Facebook SDK 4.15.1的Facebook SDK共享和共享时获得空白页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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