Facebook SDK 4.7loginerror handling

我添加了FBSDK 4.7到我的swift应用程序,当它打开safari视图控制器login,我尝试点击“完成”,而不input任何东西到电子邮件/密码字段,应用程序中断。 它吐出"fatal error: unexpectedly found nil while unwrapping an Optional value"

我如何处理这个错误?

当前login码:

 if let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager(){ fbLoginManager.logInWithReadPermissions(["email"],fromViewController:self, handler:{(result:FBSDKLoginManagerLoginResult!,error:NSError!) -> Void in if (error == nil){ let fbloginresult : FBSDKLoginManagerLoginResult = result if(fbloginresult.grantedPermissions.contains("email")) { print("Logged in successfully") self.getFBUserData() //fbLoginManager.logOut() } } else{ print("HELPPPPPPPPPP") } }) } 

不需要指定variables的types(result, error)

这里是与Facebook 4.7 SDK |的工作代码 Swift 2 | Xcode 7。

 @IBAction func btnFBLoginPressed(sender: AnyObject) { let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager() fbLoginManager.loginBehavior = FBSDKLoginBehavior.Web fbLoginManager.logInWithReadPermissions(["email"], fromViewController: self, handler: { (result, error) -> Void in if (error == nil){ let fbloginresult : FBSDKLoginManagerLoginResult = result if fbloginresult.grantedPermissions != nil { //Here we have to check that the set contains value or not if(fbloginresult.grantedPermissions.contains("email")) { self.getFBUserData() fbLoginManager.logOut() } } } }) } func getFBUserData(){ if((FBSDKAccessToken.currentAccessToken()) != nil){ FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).startWithCompletionHandler({ (connection, result, error) -> Void in if (error == nil){ print(result) } }) } } 

我们必须检查grantedPermissionsSet是否nil

 if fbloginresult.grantedPermissions != nil { //Here we have to check that the set contains value or not