拒绝权限处理Facebook登录

时间:2016-11-09 16:11:13

标签: swift facebook pfuser

我正在尝试强制我的用户提供他们的数据,以便访问我的应用。

由于Swift 3中的语法略有改变,我不得不开发它。基本上我的想法如下:

let permissions = ["public_profile", "user_birthday", "user_photos"]

PFFacebookUtils.logInInBackground(withReadPermissions: permissions, block:
{ (user, error) -> Void in

            // casting user to FBSDKLoginManagerLoginResult
            // asking for specific data declined/granted Permissions
            if let user = user as? FBSDKLoginManagerLoginResult {

            print(user.declinedPermissions)
            print(user.grantedPermissions)
        }}

永远不会调用我的打印方法。从用户(PFUser?)转换为FBSDKLoginManagerLoginResult的真正方法是什么?

1 个答案:

答案 0 :(得分:1)

尝试取回实际的FBSDKLoginManagerLoginResult而不是用户。

 let login:FBSDKLoginManager = FBSDKLoginManager()
 let permissions = ["public_profile", "user_birthday", "user_photos"]
 login.logIn(withReadPermissions: permissions, from: self) { (result: FBSDKLoginManagerLoginResult?, error: Error?) -> Void in
   if(FBSDKAccessToken.current() != nil){
       let permissions = FBSDKAccessToken.current().permissions
       print(permissions)
       //Do whatever else you need to do with the result
 }