2013-05-22 3 views
2

페이스 북 로그인에 문제가 있습니다. 내 앱에 Facebook을 통합했습니다. 처음 로그인 할 때 로그인 페이지가 표시되지만 다음 번에 " 이미 승인 된 APP_NAME "입니다.Facebook 로그인 이미 APP_NAME을 (를) 이미 승인하셨습니다.

페이스 북의 SDK에서 얻은 샘플 인 Scrumptious 튜토리얼을 확인했습니다. 또한 동일하게 작동합니다.

다른 사용자로부터 로그인하고 싶습니다. "이미 APP_NAME을 (를) 이미 승인했습니다."

어떻게 해결할 수 있습니까?

답변

0

이 코드를 앱 대리인 클래스에서 사용해보십시오.

세션이 열려 있는지 여부를 확인하고 연결을 닫을 때 장치 캐시에서 로그인 자격 증명을 지 웁니다.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    LoginVC *loginScreen=[[LoginVC alloc]initWithNibName:@"LoginVC" bundle:nil]; 

    navigationController=[[UINavigationController alloc]initWithRootViewController:loginScreen]; 

    self.navigationController.navigationBar.tintColor = [UIColor blackColor]; 
    self.window.rootViewController=self.navigationController; 
    self.window.backgroundColor = [UIColor whiteColor]; 
    [self.window makeKeyAndVisible]; 

    // See if we have a valid token for the current state. 
    if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) { 
     [self openSession]; 
     // To-do, show logged in view 
    } else { 
     // No, display the login page. 
     [self showLoginView]; 
    } 
    return YES; 


} 
- (void)sessionStateChanged:(FBSession *)session 
         state:(FBSessionState) state 
         error:(NSError *)error 
{ 
    switch (state) { 
     case FBSessionStateOpen: { 
      UIViewController *topViewController = 
      [self.navigationController topViewController]; 
      if ([[topViewController presentedViewController] 
       isKindOfClass:[LoginVC class]]) { 
       [topViewController dismissViewControllerAnimated:YES completion:nil]; 
      } 
     } 
      break; 
     case FBSessionStateClosed: 
     case FBSessionStateClosedLoginFailed: 
      // Once the user has logged in, we want them to 
      // be looking at the root view. 
      [self.navigationController popToRootViewControllerAnimated:NO]; 

      [FBSession.activeSession closeAndClearTokenInformation]; 

      [self showLoginView]; 
      break; 
     default: 
      break; 
    } 

    if (error) { 
     UIAlertView *alertView = [[UIAlertView alloc] 
            initWithTitle:@"Error" 
            message:error.localizedDescription 
            delegate:nil 
            cancelButtonTitle:@"OK" 
            otherButtonTitles:nil]; 
     [alertView show]; 
    } 
} 

- (void)openSession 
{ 
    [FBSession openActiveSessionWithReadPermissions:nil 
             allowLoginUI:YES 
            completionHandler: 
    ^(FBSession *session, 
     FBSessionState state, NSError *error) { 
     [self sessionStateChanged:session state:state error:error]; 
    }]; 
} 

- (BOOL)application:(UIApplication *)application 
      openURL:(NSURL *)url 
    sourceApplication:(NSString *)sourceApplication 
     annotation:(id)annotation 
{ 
    return [FBSession.activeSession handleOpenURL:url]; 
} 
- (void)applicationDidBecomeActive:(UIApplication *)application 
{ 
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 
    // We need to properly handle activation of the application with regards to Facebook Login 
    // (e.g., returning from iOS 6.0 Login Dialog or from fast app switching). 
    [FBSession.activeSession handleDidBecomeActive]; 
} 

이 코드가 도움이되기를 바랍니다.

관련 문제