OGeek|极客世界-中国程序员成长平台

标题: ios - 您已经授权facebook、iOS [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 19:51
标题: ios - 您已经授权facebook、iOS

现在我有一个 iOS 应用程序,它使用 facebook SDK 使用用户 facebook 帐户登录,显然你知道这一点。这是我用来做这些事情的代码。

-(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);
             }
         }];

    }
}

问题是当用户删除应用程序并安装然后再次登录时,facebook 登录对话框显示“您已经授权 {ApplicationName}”,用户必须单击确定才能返回我的应用程序。

我只希望他们只需要选项卡即可登录按钮,然后显示加载圈并成功。

有什么想法吗?



Best Answer-推荐答案


选择 1

如果你按下 Login 按钮,调用这个

删除所有授予的权限

[[[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];
     }

 }];

选择 2

如果你想清除当前 session 使用like

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

更新

如果你想绕过连接

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

swift

删除所有授予的权限

  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()
}

})

选择 2

如果你想清除当前 session 使用like

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

// then continue the same process

}

更新

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

关于ios - 您已经授权facebook、iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37084850/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4