9

我正在制作一个基于 iOS6 Social Framework 的应用程序......它运行良好,但几个月后出现了一个奇怪的错误。

我将 JSON Facebook 数据导入到 NSDictionary 的 NSLog 是:

profiledictionary: {
error = {
code = 190;
"error_subcode" = 463;
message = "Error validating access token: Session has expired at unix time 1365610034. The current unix time is 1366032783.";
type = OAuthException;

似乎我的访问令牌已过期,但 iOS6 社交框架不应该自动处理它吗?

关于如何解决它并避免将来出现此类问题的任何想法,以便我可以安全地发布一个真正的应用程序?

4

1 回答 1

13

终于明白了……有必要检查 NSDictionary 是否有一个名为“error”的对象(在这种情况下,Facebook 错误有关令牌已过期),如果是,则调用一个方法来更新 ACAccount:

if([self.profileDictionary objectForKey:@"error"]!=nil)
{
[self attemptRenewCredentials]; 
}

-(void)attemptRenewCredentials{
    [self.accountStore renewCredentialsForAccount:(ACAccount *)self.facebookAccount completion:^(ACAccountCredentialRenewResult renewResult, NSError *error){
        if(!error)
        {
            switch (renewResult) {
                case ACAccountCredentialRenewResultRenewed:
                    NSLog(@"Good to go");
                    [self getFacebookAccount];
                    break;
                case ACAccountCredentialRenewResultRejected:
                    NSLog(@"User declined permission");
                    break;
                case ACAccountCredentialRenewResultFailed:
                    NSLog(@"non-user-initiated cancel, you may attempt to retry");
                    break;
                default:
                    break;
            }

        }
        else{
            //handle error
            NSLog(@"error from renew credentials%@",error);
        }
    }];
}
于 2013-04-16T20:40:15.147 回答