【发布时间】:2013-06-18 17:32:52
【问题描述】:
在使用ACAccountStore 和ACAccount 时,有什么方法可以判断您的Facebook 令牌何时到期?
我创建了一个ACAccountStore,访问用户的Facebook 帐户,将该帐户存储在ACAccount 对象中,并且能够从凭据中检索令牌。不过,我也想知道这个令牌什么时候到期。我将如何着手取消此令牌的到期?还是有可能?
【问题讨论】:
在使用ACAccountStore 和ACAccount 时,有什么方法可以判断您的Facebook 令牌何时到期?
我创建了一个ACAccountStore,访问用户的Facebook 帐户,将该帐户存储在ACAccount 对象中,并且能够从凭据中检索令牌。不过,我也想知道这个令牌什么时候到期。我将如何着手取消此令牌的到期?还是有可能?
【问题讨论】:
您为什么想知道它什么时候到期?
当您获得令牌时,在 Facebook 的情况下,它的令牌生命周期会延长。我认为今天是额外的 60 天。因此,当您从帐户商店获得它时,应该很好。
如果用户正在使用您的应用,然后决定从 Facebook 设置本身撤消权限,您应该关注的唯一细节。
在这种情况下,您需要确保您正在监视ACAccountStoreDidChangeNotification 通知并适当地调用renewCredentialsForAccount:completion: 以再次请求权限,请参阅Documentation。
例如:
- (void)accountChanged:(NSNotification *)note
{
[self.accountStore renewCredentialsForAccount:(ACAccount *)self.facebookAccount completion:^(ACAccountCredentialRenewResult renewResult, NSError *error){
if(!error)
{
switch (renewResult) {
case ACAccountCredentialRenewResultRenewed:
// Good
break;
case ACAccountCredentialRenewResultRejected:
// Maybe go back to non logged in status
break;
case ACAccountCredentialRenewResultFailed:
// Maybe internet failed, Facebook is down?
break;
default:
break;
}
}
else{
// Handle error gracefully
}
}];
}
也许this tutorial 可能对你有所帮助。
【讨论】: