2013-12-20 83 views
0

我已經在我的應用程序中使用Facebook登錄並運行良好我正在使用Facebook sdk 3.10,但它只是將我重定向到Web瀏覽器並打開Facebook登錄頁面權限,如果已經存在會話但我不我不想用這種方式,我希望像以前的SDK中的Facebook登錄彈出窗口應該打開,在那裏我填寫我的代碼在下面的憑據請我可以改變這個做同樣的事情。用iPhone在facebook上登錄而不重定向到網絡瀏覽器?

NSArray *permissions =[NSArray arrayWithObjects:@"email",@"user_location",@"user_about_me",@"user_photos",@"xmpp_login", nil]; 
NSHTTPCookie *cookie; 
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; 
for (cookie in [storage cookies]) 
{ 
    [storage deleteCookie:cookie]; 
} 
[[NSUserDefaults standardUserDefaults] synchronize]; 
[FBSession openActiveSessionWithReadPermissions:permissions 
            allowLoginUI:YES 
           completionHandler:^(FBSession *session, 
                FBSessionState status, 
                NSError *error) 
{ 
    // if login fails for any reason, we alert 
    if (error) { 
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                 message:error.localizedDescription 
                 delegate:nil 
               cancelButtonTitle:@"OK" 
               otherButtonTitles:nil]; 
     [alert show]; 
    } 
    else if (FB_ISSESSIONOPENWITHSTATE(status)) 
    { 
     FBRequest *me = [[FBRequest alloc] initWithSession:session 
                graphPath:@"me?fields=id,picture.type(large),first_name,last_name,email,gender,birthday,username,hometown"]; 
     [me startWithCompletionHandler:^(FBRequestConnection *connection, 
              NSDictionary<FBGraphUser> *aUser, 
              NSError *error) 
     { 
      fbDetails = [[NSDictionary alloc]init]; 
      fbDetails=[aUser copy]; 
      facebookDetail = [appParser getUserFbDetail:fbDetails]; 

     }]; 
    } 
}]; 

回答

2

使用下面的方法來打開FBLogin彈出

-(void)openFacebookAuthentication 
{ 
    NSArray *permission = [NSArray arrayWithObjects:kFBEmailPermission,kFBUserPhotosPermission, nil]; 

    FBSession *session = [[FBSession alloc] initWithPermissions:permission]; 

    [FBSession setActiveSession: [[FBSession alloc] initWithPermissions:permission] ]; 

    [[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorForcingWebView completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { 

     switch (status) { 
      case FBSessionStateOpen: 
       [self getMyData]; 
       break; 
      case FBSessionStateClosedLoginFailed: { 
       // prefer to keep decls near to their use 
       // unpack the error code and reason in order to compute cancel bool 
       NSString *errorCode = [[error userInfo] objectForKey:FBErrorLoginFailedOriginalErrorCode]; 
       NSString *errorReason = [[error userInfo] objectForKey:FBErrorLoginFailedReason]; 
       BOOL userDidCancel = !errorCode && (!errorReason || [errorReason isEqualToString:FBErrorLoginFailedReasonInlineCancelledValue]); 


       if(error.code == 2 && ![errorReason isEqualToString:kFBSdkUserLoginFail]) { 
        UIAlertView *errorMessage = [[UIAlertView alloc] initWithTitle:kFBAlertTitle 
                      message:kFBAuthenticationErrorMessage 
                      delegate:nil 
                      cancelButtonTitle:kOk 
                      otherButtonTitles:nil]; 
        [errorMessage performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:YES]; 
        errorMessage = nil; 
        } 
       } 
       break; 
       // presently extension, log-out and invalidation are being implemented in the Facebook class 
      default: 
       break; // so we do nothing in response to those state transitions 
     } 
    }]; 
    permission = nil; 
} 
+0

感謝名單了很多@Divya Bhalodiya它的工作,只是一兩件事沒有選擇關閉彈出,如果我要取消登錄時出現任何選項相同 –

+2

@GaganKumar有什麼加載問題點擊左側上角有關閉按鈕,但不幸的是有些時候隱藏。 –

+0

是的,它是thanx那@NitinGohel –

相關問題