Issue
I am integrating facebook login in Swift3 language in iOS using FBSDK4.18.0.Below is the following code: But it does not prints the results including
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
print("User Logged In")
if ((error) != nil)
{
// Process error
}
else if result.isCancelled {
// Handle cancellations
}
else {
// If you ask for multiple permissions at once, you
// should check if specific permissions missing
if result.grantedPermissions.contains("public_profile")
{
// Do work
// let strFirstName: [String: Any]? = (result.objectForKey("first_name") as? String)!
// let strLastName: String = (result.objectForKey("last_name") as? String)!
// let strPictureURL: String = (result.objectForKey("picture")?.objectForKey("data")?.objectForKey("url") as? String)!
if let dic = result as? [String: Any]
{ if let strFirstName = dic["first_name"] as? String, let strLastName = dic["last_name"] as? String
{
print("\(strFirstName) \(strLastName)")
}
}
}
}
}
It also shows the "Cast from 'FBSDKLoginManagerLoginResult!' to unrelated type '[String : Any]' always fails" warning at "if let dic = result as? [String: Any]"
Solution
You should use AnyObject and not Any. More on it can be found here:
if let dic = result as? [String: AnyObject] {
if let strFirstName = dic["first_name"] as? String, let strLastName = dic["last_name"] as? String
{
print("\(strFirstName) \(strLastName)")
}
}
Answered By - Nikos M. Answer Checked By - Mary Flores (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.