尝试首次登录时,Facebook登录iOS并未打开Safari

时间:2017-05-29 07:23:01

标签: ios facebook login fbsdk

我的应用登录屏幕

enter image description here

首次尝试时,Facebook登录按钮不会打开safari浏览器,而第二次尝试则无法正常工作。

以下是我尝试过的代码:

FBSDKLoginManager *manager = [FBSDKLoginManager new];
manager.loginBehavior = FBSDKLoginBehaviorBrowser;
NSArray *permissions = @[@"email",@"public_profile"];
[manager logInWithReadPermissions:permissions fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error){

    if(error) {
        [self showAlertWith:@"Oops!" message:@"Login Failed, try again" handler:nil];
        return;
    }
    if(result.isCancelled) {
        [self showAlertWith:@"Oops!" message:@"Login Failed, try again" handler:nil];
        return;
    }else {
        [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me"
                                           parameters:@{@"fields": @"picture, name, email"}]
         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id userinfo, NSError *error) {
             if(!error) {
                 if([FBSDKAccessToken currentAccessToken]) {
                     [self makeGraphRequest];
                 }
             }else {
                 EKLog(@"error %@", error);
             }
         }];
    }
}];

第一次单击登录按钮调用loginWithReadPermission但从不调用回调块,而再次单击,则调用回调处理程序。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:2)

如果有效,你可以尝试一种解决方案!

FBSDKLoginManager *manager声明为实例变量或属性,并在viewDidload中初始化,例如,

 FBSDKLoginManager *manager = [FBSDKLoginManager new];

然后使用!!可能是因为当地宣言而发生的!