我在我的 Swift 2.3 项目中使用 Facebook SDK 4.13.1。当我尝试通过模拟器登录 Facebook 时,在使用 Facebook 授权用户时,它会成功返回用户信息。但是,当我尝试在我的 iOS 设备上执行相同操作以切换到本机 Facebook 应用程序然后返回到我的应用程序时,不会返回任何用户信息。当我尝试通过 iOS 设备上的 Safari 登录 Facebook 时,也会发生这种情况。
这个过程在模拟器以及之前的 iOS 设备上完美运行,并且我没有更新任何可能依赖的 SDK。
以下是我检索用户信息的方法:
func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
if let error = error {
print("Facebook Login Button Error: \(error.localizedDescription)")
return
}
else {
guard let accessToken:FBSDKAccessToken? = FBSDKAccessToken.currentAccessToken() else {
self.statusLabel.alpha = 0
self.statusLabel.text = "Oops! There was a problem requesting access from Facebook."
self.statusLabel.fadeIn(completion: {
(finished: Bool) -> Void in
self.statusLabel.fadeOut()
})
return
}
if accessToken?.tokenString != nil {
let credential = FIRFacebookAuthProvider.credentialWithAccessToken(FBSDKAccessToken.currentAccessToken().tokenString)
FIRAuth.auth()?.signInWithCredential(credential) { (user, error) in
if let error = error {
print(error.localizedDescription)
return
}
self.performSegueWithIdentifier("SignUpViewControllerSegue", sender: nil)
}
}
else {
print("Access Token not granted")
}
}
}
func loginButtonWillLogin(loginButton: FBSDKLoginButton!) -> Bool {
loginButton.readPermissions = ["public_profile", "email", "user_friends", "user_location"];
return true
}