ios - 当我通过设置登录时 FBSessionStateClosedLoginFailed

标签 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];
    }
}

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

最佳答案

同时添加

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

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

成功了!

所有学分都归于 Skrew 的回答。

关于ios - 当我通过设置登录时 FBSessionStateClosedLoginFailed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18190673/

相关文章:

android - 如何在 Android 项目的同一个 Activity 中将 Google Plus 和 Facebook 身份验证集成在一起?

firebase - Firebase提供程序登录无法在facebook/messenger/instagram应用内浏览器Webview中使用。错误403 : disallowed_useragent

ios - 如何在每个 x 坐标上重复一个方法

ios - 当我在没有数据漫游的国外时,为什么 iOS 会显示 "home"位置?

ios - Swift 4 中 [MoveCommand] 的替代品是什么

iphone - FB Singleton登录

android - 为 Netbeans 设置 Android-Facebook sdk

facebook - 获取 fb.me 网址

ios - 具有自定义 anchor 的 UICollectionViewFlowLayout Cell 重用过早

ios - 当 iOS 应用程序处于后台时使用 POST-API 上传图像