我正在尝试使用FB SDK登录。但是,偶尔会有一个已经登录的用户。下面是我用来首先注销的代码。
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logOut];
[loginManager logInWithReadPermissions:permissionsArray fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
}
我想知道两件事:
1)下面的语句会遇到竞争条件吗?
2)如果是这样,我应该以及如何使登出同步以避免这种情况?
我认为这个问题的更好的解决方案是检查currentAccessToken
是否为nil并进行相应的管理。
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
if ([FBSDKAccessToken currentAccessToken]) {
// It will be synchronous and will present an alert controller which will further confirm you to logout and will set token and profile to nil.
[loginManager logOut];
//after logout you can change your LogOut Button to Login Facebook as done in Facebook samples.
} else {
// if the token is nil, just make a login call
[loginManager logInWithReadPermissions:permissionsArray fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
}
}