0

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. error in code

Sourabh Sharma
  • 7,426
  • 4
  • 62
  • 75

2 Answers2

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.

VeganKid
  • 457
  • 5
  • 16
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()
                    }
                }

            })
        }
Sourabh Sharma
  • 7,426
  • 4
  • 62
  • 75