我在我的项目中使用了一个开源应用程序示例。
当我更改info.plist中的Facebook凭据时,我得到“以未捕获的异常错误终止”。
但是当我恢复到默认值(在初始开源应用程序中使用)时,我没有遇到任何崩溃/错误,应用程序运行顺畅。
我无法从这段代码中找出异常,有人可以帮忙吗?
@IBAction func facebookLogin(sender: UIButton) {
PFFacebookUtils.logInWithPermissions(["public_profile", "email", "user_friends"], block: { (user: PFUser!, error: NSError!) -> Void in
if user != nil {
if user[PF_USER_FACEBOOKID] == nil {
self.requestFacebook(user)
} else {
self.userLoggedIn(user)
}
} else {
if error != nil {
println(error)
if let info = error.userInfo {
println(info)
}
}
MBProgressHUD.showError("Facebook sign in error")
}
})
}
func requestFacebook(user: PFUser) {
var request = FBRequest.requestForMe()
request.startWithCompletionHandler { (connection: FBRequestConnection!, result: AnyObject!, error: NSError!) -> Void in
if error == nil {
var userData = result as! [String: AnyObject]!
self.processFacebook(user, userData: userData)
} else {
PFUser.logOut()
}
}
}
func processFacebook(user: PFUser, userData: [String: AnyObject]) {
let facebookUserId = userData["id"] as! String
var link = "http://graph.facebook.com/\(facebookUserId)/picture"
let url = NSURL(string: link)
var request = NSURLRequest(URL: url!)
let params = ["height": "150", "width": "150", "type": "square"]
Alamofire.request(.GET, link, parameters: params).response() {
(request, response, data, error) in
if error == nil {
var image = UIImage(data: data! as! NSData)!
if image.size.width > 280 {
image = Images.resizeImage(image, width: 280, height: 280)!
}
var filePicture = PFFile(name: "picture.jpg", data: UIImageJPEGRepresentation(image, 0.6))
filePicture.saveInBackgroundWithBlock({ (success: Bool, error: NSError!) -> Void in
if error != nil {
println("Error saving photo")
}
})
if image.size.width > 60 {
image = Images.resizeImage(image, width: 60, height: 60)!
}
var fileThumbnail = PFFile(name: "thumbnail.jpg", data: UIImageJPEGRepresentation(image, 0.6))
fileThumbnail.saveInBackgroundWithBlock({ (success: Bool, error: NSError!) -> Void in
if error != nil {
prinln("Error saving thumbnail")
}
})
user[PF_USER_EMAILCOPY] = userData["email"]
user[PF_USER_FULLNAME] = userData["name"]
user[PF_USER_FULLNAME_LOWER] = (userData["name"] as! String).lowercaseString
user[PF_USER_FACEBOOKID] = userData["id"]
user[PF_USER_PICTURE] = filePicture
user[PF_USER_THUMBNAIL] = fileThumbnail
user.saveInBackgroundWithBlock({ (succeeded: Bool, error: NSError!) -> Void in
if error == nil {
self.userLoggedIn(user)
} else {
PFUser.logOut()
if let info = error!.userInfo {
ProgressHUD.showError("Login error")
println(info["error"] as! String)
}
}
})
} else {
PFUser.logOut()
if let info = error!.userInfo {
prinln("Failed to fetch Facebook photo")
println(info["error"] as! String)
}
}
}
}
这是我在应用程序崩溃时得到的结果:“***因未捕获的异常而终止应用程序'NSInvalidArgumentException',原因:'不能在PFObject上使用nil作为键或值。使用NSNull
.... libc ++ abi.dylib:以NSException类型的未捕获异常终止“
答案 0 :(得分:0)
在黑暗中拍摄: 它与链接中的转义序列有关:
<强> \ 强>(facebookUserId) ?