NSInvalidArgumentException 与 FBSDKGraphRequest

NSInvalidArgumentException with FBSDKGraphRequest

我遇到以下异常:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary imagePathForPictureMode:size:]: unrecognized selector sent to instance 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)

currentProfile 是在 SDK 获得访问令牌后异步获取的,因此根据您请求 currentProfile 的时间,它可能为零。

您还可以观察 FBSDKProfileDidChangeNotification 配置文件何时更新。参见 https://developers.facebook.com/docs/reference/ios/current/class/FBSDKProfile/