9

私は iOS6 Social Framework に基づいてアプリを作成しています...正常に動作していましたが、数か月後に奇妙なエラーが発生しました。

NSDictionary にインポートされた JSON Facebook データの私の 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 Social Framework が自動的に処理するはずではありませんか?

どうすればそれを解決し、そのような将来の問題を回避できるので、実際のアプリを安全に公開できるかについてのアイデアはありますか?

4

1 に答える 1

13

最終的に取得しました... NSDictionary に「エラー」という名前のオブジェクトがあるかどうかを確認する必要がありました (この場合、トークンの期限切れに関する Facebook エラー)。

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 に答える