加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

objective-c – Facebook SDK 3.1 iOS:如果用户从Facebook设置

发布时间:2020-12-16 05:29:03 所属栏目:百科 来源:网络整理
导读:我想把一些Facebook整合到我的应用程序中.在这一点上,我已经设法登录,发贴到朋友的墙上,检索朋友列表等.除了一件事外,一切都OK 如果用户从your Facebook settings / Applications删除该应用程序 然后进入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...
    }];
            }
        }
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读