2013-03-13 107 views
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]; 
} 

回答

6

你可能有您的设备上有应用程序的Info.plist同Facebook的URL方案的两个应用程序。您可以:

  • 删除旧的应用程序,或
  • 重新安装旧的应用程序,但是从Info.plist文件中删除Facebook的URL方案事先

你可能有多个URL方案。如果是这样,你应该寻找一个看起来像fbxxxxxxxxxxx,这是显示在您的应用程序页上http://developers.facebook.com/

+0

原来我有多个URL方案,解决了问题吧!非常感谢。 – 2013-03-14 06:13:45

+0

我发现我有两个应用程序具有相同的Facebook URL方案,并且我更改了url方案,但没有发生任何事情,仍然打开另一个应用程序。 – 2015-10-13 14:36:02

相关问题