5
我的iOS應用程序使用Facebook進行登錄,但是我的開發團隊最近決定將所有應用程序整合到一個具有通用APP ID的通用Facebook應用程序中。所以我進入了我的項目並嘗試將我的FacebookAppID和URL類型更改爲正確的APP ID,但是當我運行該應用程序並單擊登錄按鈕時,它會重定向我登錄到我在Facebook上的舊應用程序。我絕對不知道爲什麼發生這種情況,但這裏是我在我的AppDelegate文件:Facebook在iOS上登錄錯誤的應用程序
/*
Callback for session changes
*/
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
switch (state) {
case FBSessionStateOpen:
if (!error) {
// We have a valid session
NSLog(@"User session found");
}
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}
[[NSNotificationCenter defaultCenter]
postNotificationName:FBSessionStateChangedNotification
object:session];
if (error) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}
/*
* Opens a Facebook session and optionally shows the login UX.
*/
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"email",
@"user_games_activity",
@"user_location",
@"user_likes",
@"user_birthday",
nil];
return [FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];
}
/*
* If we have a valid session at the time of openURL call, we handle
* Facebook transitions by passing the url argument to handleOpenURL
*/
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
return [FBSession.activeSession handleOpenURL:url];
}
/*
*Logout
*
*/
- (void) closeSession {
[FBSession.activeSession closeAndClearTokenInformation];
}
原來我有多個URL方案,解決了問題吧!非常感謝。 – 2013-03-14 06:13:45
我發現我有兩個應用程序具有相同的Facebook URL方案,並且我更改了url方案,但沒有發生任何事情,仍然打開另一個應用程序。 – 2015-10-13 14:36:02