2013-02-15 315 views
2

我關注了Facebook的Scruptious示例,並在授權應用程序時遇到問題。Facebook登錄失敗

當我運行應用程序並且用戶登錄到本地Facebook應用程序時,應用程序的授權完美 - 用戶被帶到本機應用程序,授權並返回到應用程序。但是,如果用戶未登錄Facebook應用程序,則系統會要求他登錄,但不會要求授權,並且用戶仍留在Facebook應用程序中。問題: 1.這是一個FB錯誤,有什麼方法可以解決它嗎? 2.我按下home鍵,然後再次打開該應用程序 - 我的預期

- (void)applicationDidBecomeActive:(UIApplication *)application { 

    [FBSession.activeSession handleDidBecomeActive]; 
} 

通過重試照顧授權失敗的,但什麼都沒有發生。

有關如何解決這個問題的任何建議,請不勝感激。

回答

0

我認爲你缺少的更新創建會話(登錄)

你有這樣的事情後:

AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate]; 

// this button's job is to flip-flop the session from open to closed 
if (appDelegate.session.isOpen) { 
    // if a user logs out explicitly, we delete any cached token information, and next 
    // time they run the applicaiton they will be presented with log in UX again; most 
    // users will simply close the app or switch away, without logging out; this will 
    // cause the implicit cached-token login to occur on next launch of the application 
    [appDelegate.session closeAndClearTokenInformation]; 

} else { 
    if (appDelegate.session.state != FBSessionStateCreated) { 
     // Create a new, logged out session. 
     appDelegate.session = [[FBSession alloc] init]; 
    } 

    // if the session isn't open, let's open it now and present the login UX to the user 
    [appDelegate.session openWithCompletionHandler:^(FBSession *session, 
                FBSessionState status, 
                NSError *error) { 
     // and here we make sure to update our UX according to the new session state 
     [self updateView]; 
    }]; 
} 

要記住,做[self updateView];

Assumming您UpdateView就是這樣的:

- (void)updateView { 
// get the app delegate, so that we can reference the session property 
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate]; 
if (appDelegate.session.isOpen) {   
    // valid account UI is shown whenever the session is open 
    [self.buttonLoginLogout setTitle:@"Log out" forState:UIControlStateNormal];   
    [self.textNoteOrLink setText:[NSString stringWithFormat:@"https://graph.facebook.com/me/friends?access_token=%@", appDelegate.session.accessTokenData.accessToken]]; 

    [self performSegueWithIdentifier:@"inicio" sender:self]; 
} else {   
    // login-needed account UI is shown whenever the session is closed 
    [self.buttonLoginLogout setTitle:@"Log in" forState:UIControlStateNormal];   
    [self.textNoteOrLink setText:@"Login to create a link to fetch account data"];   
} 

}