当我通过设置登录时出现FBSessionStateClosedLoginFailed状态

4

我有一个应用程序,其中包含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];
    }
}

并且在Delegate中有一个名为sessionStateChanged的函数。

- (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];
    }
}

我真心希望你能帮助我,因为我不理解这个疯狂的问题。谢谢!


3
这是一个相当古老的帖子,我猜它在此期间已经解决了,但为了历史记录:请确保你们两个都添加了以下代码到你们的应用代理中:- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url { return [FBSession.activeSession handleOpenURL:url]; }- (void)applicationDidBecomeActive:(UIApplication *)application { [FBSession.activeSession handleDidBecomeActive]; } - Skrew
1个回答

3

添加两个数

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

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

操作成功!

这个答案的所有功劳都归于Skrew。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接