Facebook SDK 3.1 iOS:如果用户从Facebook设置中删除应用程序,则处理登录 [英] Facebook SDK 3.1 iOS: Handle login if user remove app from Facebook Settings

查看:130
本文介绍了Facebook SDK 3.1 iOS:如果用户从Facebook设置中删除应用程序,则处理登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用中加入一些Facebook集成。在这一点上,我已经设法登录,发布到朋友的墙上,检索朋友列表,等等。除了一件事,一切都好......

I want to put some Facebook integration in my app. At this point I've managed to login, post to friends wall, retrieve the list of friends, etc. Everything is OK except for one thing...

如果用户从您的Facebook设置/应用程序
中删除该应用程序,然后进入iOS应用程序,代码无法识别Facebook应用程序已从用户设置中删除并假设已登录(这是问题,因为如果用户尝试发布到朋友的墙上,该应用程序什么都不做)。

If the user removes the app from your Facebook settings / Applications and then enters to the iOS app, the code doesn't recognize that the Facebook app was removed from the user settings and assumes that is logged in (this is the problem because if the user tries to post to a friend's wall, the app do nothing).

然后,用户关闭iOS应用程序并重新启动它...通过此重新启动,iOS应用程序已修复并检测到用户不再登录。

Then, the user closes the iOS app and relaunches it... With this relaunch, the iOS app "is fixed" and detects that the user is no longer logged in.

我无法在用户从设置中删除Facebook应用程序后立即检测到该时刻,以便将登录流程带给用户...

I can't manage to detect the moment right after the user deletes the facebook app from the settings in order to bring the login flow to the user...

这是我的代码:

我应用的第一个场景......

if([FBSession activeSession].state == FBSessionStateCreatedTokenLoaded)
{
    NSLog(@"Logged in to Facebook");
    [self openFacebookSession];
    UIAlertView *alertDialog;

    alertDialog = [[UIAlertView alloc] initWithTitle:@"Facebook" message:@"You're already logged in to Facebook" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];

    [alertDialog show];

    [alertDialog release];
    return YES;
}
else{
    NSLog(@"Not logged in to Facebook"); //Show the login flow
    return NO;
}

这是openFacebookSession的代码

-(void)openFacebookSession
{
    NSArray *permissions = [[NSArray alloc] initWithObjects:
                            @"publish_stream",
                            nil];

    [FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
        [self sessionStateChanged:session state:status error:error];
    }];
}

sessionStateChanged的代码......

-(void)sessionStateChanged:(FBSession *)session state:(FBSessionState)state error:(NSError *)error
{
    switch (state) {
        case FBSessionStateOpen: {
            NSLog(@"Session opened");
        }
            break;
        case FBSessionStateClosed:
        case FBSessionStateClosedLoginFailed:
            [FBSession.activeSession closeAndClearTokenInformation];
            break;
        default:
            break;
    }

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

非常感谢!

推荐答案

我发现这也发生在我自己身上......当用户更改了他们的Facebook密码时,我们发现了这一点,我们无法再进行身份验证。手动重新同步/清除帐户会话允许他们再次登录。

I found this happening to myself as well.... It was discovered when a user changed their facebook password, and we could no longer authenticate. Doing a manual resync / clear of the account session allowed them to login again.

-(void)syncFacebookAccount
 {
    [self forceLogout];
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];
    ACAccountType *accountTypeFB = [accountStore         accountTypeWithAccountTypeIdentifier:@"com.apple.facebook"];
    if (accountStore && accountTypeFB) {
    NSArray *fbAccounts = [accountStore accountsWithAccountType:accountTypeFB];
    id account;
    if (fbAccounts && [fbAccounts count] > 0 && (account = [fbAccounts objectAtIndex:0])) {
    [accountStore renewCredentialsForAccount:account completion:^(ACAccountCredentialRenewResult renewResult, NSError *error) {
                    // Not actually using the completion handler...
    }];
            }
        }
    }

这篇关于Facebook SDK 3.1 iOS:如果用户从Facebook设置中删除应用程序,则处理登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆