我想使用 FacebookSDK 实现功能。
作为示例应用程序,您可以检查 url:
https://developers.facebook.com/docs/facebook-login/handling-declined-permissions#reprompt
我已经编写了这段代码,但它并没有像预期的那样对我有用。
//Callback function for default FBLogin Button
func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!)
{
print("User Logged In")
if (error != nil)
{
// Process error
print("Processing Error : \(error)")
FBSDKLoginManager().logOut()
self.dismissViewControllerAnimated(true, completion: nil)
}
else if result.isCancelled
{
// Handle cancellations
print("user is cancelled the login FB")
FBSDKLoginManager().logOut()
self.dismissViewControllerAnimated(true, completion: nil)
}
else
{
print("result : \(result)")
// If you ask for multiple permissions at once, you
// should check if specific permissions missing
if result.declinedPermissions.contains("email")
{
print("email is declined")
// Do work
loginManager = FBSDKLoginManager()
loginManager!.logInWithReadPermissions(["email"], fromViewController: self, handler:{ [unowned self](result, error) -> Void in
if error == nil
{
self.fetchUserData()
}
})
}
else
{
var readPermissions : FBSDKLoginManagerLoginResult = result
Constants.isUserLoggedIn = true
fetchUserData()
}
}
}