• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 您已经授权facebook、iOS

[复制链接]
菜鸟教程小白 发表于 2022-12-12 19:51:09 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

现在我有一个 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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap