2017-05-29 213 views
2

我的應用程序登錄屏幕在不打開Safari瀏覽器,Facebook登錄嘗試登錄首次

enter image description here

在第一次嘗試Facebook登錄按鈕沒有打開Safari瀏覽器,而在第二嘗試它工作正常。

下面是我試過的代碼:首次將loginWithReadPermission的調用,但回調塊從未被稱爲

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

點擊登錄按鈕,而再次點擊,回調處理程序被調用。任何幫助,將不勝感激。

+0

請參閱:https://stackoverflow.com/a/40089906/3901620 – KKRocks

回答

2

如果工作正常,您可以嘗試一種解決方案!

聲明FBSDKLoginManager *manager爲實例變量或屬性和viewDidload像初始化,

FBSDKLoginManager *manager = [FBSDKLoginManager new]; 

然後用!這可能是因爲當地的宣言而發生的!