I am new to swift, How to resolve this error of optional "fatal error: unexpectedly found nil while unwrapping an Optional value". This error occurs when i cancelled the Facebook login process.
Asked
Active
Viewed 202 times
0
![](../../users/profiles/3933302.webp)
Sourabh Sharma
- 7,426
- 4
- 62
- 75
-
It may helps you: http://stackoverflow.com/a/24643643/988169 – pkc456 Oct 12 '15 at 08:49
2 Answers
0
Change that line to an if let
and if you fail that check it probably means you canceled the login process, since grantedPermissions were never... granted!
In the else
block handle when a user cancels the login process. Hope this helped.
![](../../users/profiles/2604620.webp)
VeganKid
- 457
- 5
- 16
-
thanks but I know that it can be solved by if let binding but how? for Bool – Sourabh Sharma Oct 12 '15 at 08:54
0
This error occurred because i was not handling the canceling event.
@IBAction func FBAction(sender: AnyObject) {
let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
fbLoginManager.logInWithReadPermissions(["email"], fromViewController: self, handler:{ (result, error) -> Void in
if ((error) != nil){
// Process error
}
else if result.isCancelled {
// Handle cancellations
//This method ; I should have implemented
}
else {
let fbloginresult : FBSDKLoginManagerLoginResult = result
if(fbloginresult.grantedPermissions.contains("email"))
{
self.getFBUserData()
fbLoginManager.logOut()
}
}
})
}
![](../../users/profiles/3933302.webp)
Sourabh Sharma
- 7,426
- 4
- 62
- 75