我正在制作一个基于iOS6社交框架的应用程序...它工作正常但现在几个月后出现了一个奇怪的错误。
我导入的JSON Facebook数据的NSLog到NSDictionary是:
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社交框架是不是应该自动处理它?</ p>
关于我如何解决它并避免将来出现这类问题的任何想法,以便我可以安全地发布真正的应用程序?
答案 0 :(得分: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);
}
}];
}