我遇到以下异常:
由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [__ NSCFDictionary imagePathForPictureMode:size:]:无法识别的选择器发送到实例0x7ff9f8d25d10'
使用此代码:
PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions, block: {
(user: PFUser?, error: NSError?) -> Void in
if let user = user {
if user.isNew {
var request = FBSDKGraphRequest(graphPath: "me", parameters: nil)
request.startWithCompletionHandler({
(connection, result, error) -> Void in
if error == nil {
// exception thrown next line
let strProfilePicURL = result.imagePathForPictureMode(FBSDKProfilePictureMode.Square, size: self.profileImage.frame.size)
let url = NSURL(string: strProfilePicURL, relativeToURL: NSURL(string: "http://graph.facebook.com/"))
let imageData = NSData(contentsOfURL: url!)
let image = UIImage(data: imageData!)
self.profileImage.image = image!
}
})
println("User signed up and logged in through Facebook!")
} else {
println("User logged in through Facebook!")
}
} else {
println("Uh oh. The user cancelled the Facebook login.")
}
})
为什么在这里抛出异常?我也试过了:
let size = self.profileImage.frame.size as CGSize
let strProfilePicURL = result.imagePathForPictureMode(FBSDKProfilePictureMode.Square, size: size)
答案 0 :(得分:2)
在SDK获取访问令牌后异步提取currentProfile
,因此根据您要求currentProfile
的时间,它可能为零。
您还可以在更新个人资料时观察FBSDKProfileDidChangeNotification
。见https://developers.facebook.com/docs/reference/ios/current/class/FBSDKProfile/