I use the following code to login to facebook:
@IBAction func fbLoginBtnDidTouch(sender: AnyObject) { let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager() fbLoginManager.logInWithReadPermissions(["email"], fromViewController: self) { (result, error) -> Void in if (error == nil){ let fbloginresult : FBSDKLoginManagerLoginResult = result if(fbloginresult.grantedPermissions.contains("email")) { self.getFBUserData() } } } }
AppDelegate:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) } func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) }
This will launch FB in web browsing. If the user accepts the application from the FB account, he will return to the application as expected.
But if the user clicks NO or clicks Finish in the web browser using FB, the application will crash (fatal error: zero was unexpectedly found when deploying an optional value)
Marking this line:
if(fbloginresult.grantedPermissions.contains("email"))
So, why does the application crash if the user clicks the No or Finish button?
source share