【发布时间】:2013-11-29 04:22:44
【问题描述】:
我开发了一个与 Facebook 集成的应用程序,我正在测试多个登录失败的场景。然后我看到了一个卡住我的人。
场景是:
- 用户使用他的帐户配置了 iOS 6 SSO。
- 然后用户打开应用程序,不要授权它。
- 然后用户从 iOS 中删除他的 Facebook 帐户。
结果:
应用程序卡住了,因为它正在获取未经授权的信息,我无法再更改它,因为 Facebook 帐户不再集成到 iOS。
我的问题是:
我需要知道用户是否在 iOS 上设置了他的 Facebook 凭据(设置 > Facebook)。 我怎么知道?我搜索了 Facebook 文档并没有找到。
这是我的代码:
+ (void)initFacebook:(void (^)(int))initResult
{
NSLog(@"init: activeSession.state = %i", FBSession.activeSession.state);
[FBSession renewSystemCredentials:^(ACAccountCredentialRenewResult result, NSError *error) {
if (result == ACAccountCredentialRenewResultFailed) {
//User has changed his password and must update his iOS login credentials
NSLog(@"sync: ACAccountCredentialRenewResultFailed -- error.code = %i", error.code);
//Display some message to user…
//Get rid of the token with wrong credentials
[FBSession.activeSession closeAndClearTokenInformation];
FBSession.activeSession = [[FBSession alloc] init];
initResult(1);
}
else if (result == ACAccountCredentialRenewResultRejected) {
//User has unauthorized my App in Settings > Facebook
NSLog(@"sync: ACAccountCredentialRenewResultRejected -- error.code = %i", error.code);
//Display some message to user…
//Get rid of the token with wrong credentials
[FBSession.activeSession closeAndClearTokenInformation];
FBSession.activeSession = [[FBSession alloc] init];
initResult(2);
}
else if (result == ACAccountCredentialRenewResultRenewed) {
//Everything is fine with iOS credentials
NSLog(@"sync: ACAccountCredentialRenewResultRenewed -- error.code = %i", error.code);
//Just to be sure that the session state is right
if (FBSession.activeSession.state == FBSessionStateCreated ||
FBSession.activeSession.state == FBSessionStateCreatedOpening ||
FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
//Open the active session
[FBSession openActiveSessionWithReadPermissions:@[@"basic_info", @"user_photos"]
allowLoginUI:YES
completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
NSLog(@"opensession: activeSession.state = %i", FBSession.activeSession.state);
}];
}
}
}];
}
谢谢!
【问题讨论】:
标签: ios facebook facebook-ios-sdk