我已将错误缩小到此代码块。我需要在可选项中定义一些内容,但我不知道在哪里。
@IBAction func SignupWithFacebook(sender: AnyObject) {
var permissionsArray = ["user_about_me", "user_birthday", "email"]
PFFacebookUtils.logInWithPermissions(permissionsArray, block: { (user: PFUser?, error: NSError!) -> Void in
if (user == nil) {
let errormessage = error.userInfo!["error"] as NSString
var facebookLoginError = UIAlertController(title: "Error While Logging", message: "\(errormessage)", preferredStyle: .Alert)
var okButton = UIAlertAction(title: "OK", style: .Default, handler: nil)
facebookLoginError.addAction(okButton)
self.presentViewController(facebookLoginError, animated: true, completion: nil)
}
})
}
非常感谢任何帮助。
答案 0 :(得分:0)
您的代码假定如果用户为nil则会出现错误。我不知道你能不能保证。试试这个:
@IBAction func SignupWithFacebook(sender: AnyObject) {
let permissionsArray = ["user_about_me", "user_birthday", "email"]
PFFacebookUtils.logInWithPermissions(permissionsArray) { (user, error) -> Void in
if user == nil {
if let e = error {
let errormessage = e.userInfo!["error"] as NSString
let facebookLoginError = UIAlertController(title: "Error While Logging", message: "\(errormessage)", preferredStyle: .Alert)
let okButton = UIAlertAction(title: "OK", style: .Default, handler: nil)
facebookLoginError.addAction(okButton)
self.presentViewController(facebookLoginError, animated: true, completion: nil)
}
}
}
}