Get blank page while log in, share and like with Facebook SDK on iOS 10 with Facebook SDK 4.15.1

拜拜、爱过 提交于 2019-12-10 21:36:51

问题


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"];
}

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];
        }

}

Using FBSDKShareKit to Like:

FBSDKLikeButton *like = [[FBSDKLikeButton alloc] init];
like.objectID = @"";
like.frame = CGRectOffset(like.frame, 50, 100);
[self.view addSubview:like];

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?


回答1:


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];

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

self.socialWindow.hidden = YES;


来源:https://stackoverflow.com/questions/39544752/get-blank-page-while-log-in-share-and-like-with-facebook-sdk-on-ios-10-with-fac

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!