Facebook sdk 4.1.0注销无法正常工作

时间:2015-08-15 05:36:50

标签: ios objective-c facebook logout

我正在使用以下代码从应用程序注销。

   [[FBSDKLoginManager new] logOut];

   if ([FBSDKAccessToken currentAccessToken]) {
      [FBSDKAccessToken setCurrentAccessToken:nil];
      [FBSDKProfile setCurrentProfile:nil];
   }

仍然选择旧的个人资料登录。如果我杀了应用程序并重新开始,那么它工作正常。

有什么建议我做错了吗?

登录代码 -

         FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];         
     [login logInWithReadPermissions:@[@"user_birthday",@"public_profile",@"user_friends",@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {

        if (error) {
           // Process error
        } else if (result.isCancelled) {
           // Handle cancellations
        } else {
           if ([result.grantedPermissions containsObject:@"email"]) {

              // Do work
              NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/me?access_token=%@",result.token.tokenString]]];

              //Start the request for the data
              [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
                 NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
                 NSDictionary *jsonDict = [jsonString JSONValue];
                 [self getFBUserDetailFinished:jsonDict];
              }];
           }
        }
     }];

1 个答案:

答案 0 :(得分:0)

使用此代码:

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logOut];

另一种方式:您在注销方法调用后获得facebook用户信息,第二次注册,然后获取用户数据中没有问题提取。

- (IBAction)btnFacebookPressed:(id)sender {
    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    [login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
     {
         if (error)
         {
             // Process error
         }
         else if (result.isCancelled)
         {
             // Handle cancellations
         }
         else
         {
             if ([result.grantedPermissions containsObject:@"email"])
             {
                 NSLog(@"result is:%@",result);
                 [self fetchUserInfo];
                 [login logOut];
             }
         }
     }];
}

-(void)fetchUserInfo
{
    if ([FBSDKAccessToken currentAccessToken])
    {
        NSLog(@"Token is available : %@",[[FBSDKAccessToken currentAccessToken]tokenString]);

        [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, link, first_name, last_name, picture.type(large), email, birthday, bio ,location ,friends ,hometown , friendlists"}]
         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
             if (!error)
             {
                 NSLog(@"resultis:%@",result);
             }
             else
             {
                 NSLog(@"Error %@",error);
             }
         }];

    }

}