简体   繁体   中英

You have already authorized facebook, iOS

Now I have an iOS Application that using facebook SDK to login using user facebook account, obviously you know that. And here is my code which i use to do this stuff.

-(void)loginButtonClicked
{
    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
    [login logInWithReadPermissions:@[@"email"] fromViewController:self 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];
             }
         }
     }];
}

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

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

    }
}

Problem is when user deleted app and they install then signin back again, the dialog of facebook login show "You have already authorized {ApplicationName}" and user must click OK to return my app.

All I want that they only need tab to login button then a loading circle show up and success.

Any idea to do that?

Choice-1

if you press the Login button, call this

delete all granted permisson

[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me/permissions" parameters:nil 
HTTPMethod:@"DELETE"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {

 if (error)
     {
         // Process error
     }
     else if (result.isCancelled)
     {
         // Handle cancellations
     }
     else
     {
      // call your login action and create the new session
       [self loginButtonClicked];
     }

 }];

Choice-2

if you want to clear the current session use like

-(void)loginButtonClicked
{
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logOut];
[FBSDKAccessToken setCurrentAccessToken:nil];
// then continue the same process

update

if you want to bypass the connection

 -(void)loginButtonClicked
{
if FBSDKAccessToken.currentAccessToken != nil
{
  // already logged in with the requested permissions 
}
else
{
  // start the login process
}
}

Swift

delete all granted permisson

  FBSDKGraphRequest(graphPath: "me/permissions", parameters: nil,  HTTPMethod: "DELETE").startWithCompletionHandler({(connection:  FBSDKGraphRequestConnection, result: AnyObject, error: NSError) -> Void in
if error! {
    // Process error
}
else if result.isCancelled {
    // Handle cancellations
}
else {
    // call your login action and create the new session
    self.loginButtonClicked()
}

})

Choice-2

if you want to clear the current session use like

func loginButtonClicked() {
var login: FBSDKLoginManager = FBSDKLoginManager()
login.logOut()
FBSDKAccessToken.currentAccessToken = nil

// then continue the same process

}

update

func loginButtonClicked() {
if FBSDKAccessToken.currentAccessToken != nil {
    // already logged in with the requested permissions
}
else {
    // start the login process
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM