0
我不知道如何处理这个案例,当iOS FBSDK给我一个过期的令牌。在我的应用程序中,我点击“登录”按钮时调用以下方法。如何处理FBSDK令牌过期的情况?
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"public_profile", @"email", @"user_photos", @"user_birthday"]
fromViewController:nil
handler: etc.... ]
这则触发FBSDKAccessTokenDidChangeNotification,而我HANDELING这种方法如下:
- (void)fbAccessTokenDidChange:(NSNotification *)notification
{
if ([notification.name isEqualToString:FBSDKAccessTokenDidChangeNotification]) {
FBSDKAccessToken* oldToken = [notification.userInfo valueForKey: FBSDKAccessTokenChangeOldKey];
FBSDKAccessToken* newToken = [notification.userInfo valueForKey: FBSDKAccessTokenChangeNewKey];
NSLog(@"FB access token did change notification\nOLD token:\t%@\nNEW token:\t%@", oldToken.tokenString, newToken.tokenString);
// initial token setup when user is logged in
if (newToken != nil && oldToken == nil)
{
NSDate *nowDate = [NSDate date];
NSDate *fbExpirationDate = [FBSDKAccessToken currentAccessToken].expirationDate;
if ([fbExpirationDate compare:nowDate] != NSOrderedDescending)
{
NSLog(@"FB token: expired");
if ([FBSDKAccessToken currentAccessToken])
{
[[FBSDKLoginManager new] logOut];
[[NSNotificationCenter defaultCenter] postNotificationName:@"fbTokenExpired" object:nil];
}
return;
}
[self storeFacebookToken];
}
else if (newToken && oldToken && ![oldToken.tokenString isEqualToString:newToken.tokenString])
{
NSLog(@"FB access token string did change");
[self storeFacebookToken];
}
}
}
什么我需要为caase做令牌已过期? ??我正在调用[[FBSDKLoginManager new] logOut],它将当前令牌设置为nil。但是,当我再次将用户重定向到登录按钮操作时,会出现同一个窗口,要求用户按'允许'。这并不是要求用户输入他的密码和电子邮件,这从我的理解会产生一个新的令牌?我错在哪里?现在用户只是进入循环从未登录...
任何帮助很感谢!日Thnx
Thnx但这不是一个好的解决方案。我应该如何向用户展示?我需要以某种方式在后台以编程方式执行此操作,而不是告诉用户去fb应用程序并注销... – user1974507