objective-c – Facebook SDK 3.1 iOS:如果用户从Facebook设置中删除应用,请处理登录

前端之家收集整理的这篇文章主要介绍了objective-c – Facebook SDK 3.1 iOS:如果用户从Facebook设置中删除应用,请处理登录前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想把一些Facebook整合到我的应用程序中.在这一点上,我已经设法登录,发贴到朋友的墙上,检索朋友列表等.除了一件事外,一切都OK

如果用户your Facebook settings / Applications删除该应用程序
然后进入iOS应用程序,代码不会识别Facebook应用程序已从用户设置中删除,并假定已登录(这是问题,因为如果用户尝试发布到朋友的墙上,应用程序会没有).

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

用户从设置中删除Facebook应用程序后才能立即检测到该时刻,以便将登录流程提供给用户

这是我的代码

我的应用程序的第一幕

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密码,我们不能再认证.手动重新同步/清除帐户会话允许他们再次登录.
-(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...
    }];
            }
        }
    }
原文链接:https://www.f2er.com/c/114639.html

猜你在找的C&C++相关文章