我有以下例外:
由于未捕获的异常“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)

最佳答案

在sdk获得访问令牌后,将异步获取currentProfile,因此根据您请求currentProfile的时间,它可能为零。
您还可以观察配置文件更新时的FBSDKProfileDidChangeNotification。见https://developers.facebook.com/docs/reference/ios/current/class/FBSDKProfile/

10-08 08:40