我通过“设置”登录时FBSessionStateClosedLoginFailed

时间:2013-08-12 15:15:33

标签: ios facebook

我有一个与facebook集成的应用程序,有时一切正常,但现在我收到一些人无法登录Facebook的邮件。

现在我现在出现了什么问题。

如果我没有通过我的Facebook帐户中的设置登录,一切正常,但当我通过设置登录时,我总是进入sessionStateChanged功能案例FBSessionStateClosedLoginFailed:

我能对此做些什么?

这是我的代码:

首先,当我点击登录Facebook时,我使用此功能:

- (void)facebookLoginFunction {
    if ([self checkInternet]==TRUE) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sessionStateChanged:) name:FBSessionStateChangedNotification object:nil];
        AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];
        // The person using the app has initiated a login, so call the openSession method
        // and show the login UX if necessary.
       [appDelegate openSessionWithAllowLoginUI:YES];
    }
}

和函数sessionStateChanged:在Delegate

- (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: NSLog(@"User session closed");
        case FBSessionStateClosedLoginFailed:{ NSLog(@"Login failed");
            [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];
    }
}

我真的希望你能帮助我,因为我不明白这个疯狂的问题。 感谢

1 个答案:

答案 0 :(得分:3)

同时添加

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url   
{   
return [FBSession.activeSession handleOpenURL:url];   
}    

- (void)applicationDidBecomeActive:(UIApplication *)application   
{   
[FBSession.activeSession handleDidBecomeActive];   
}

工作!

所有学分都转到了这个答案。