2015-04-30 51 views
2

,我發現了以下異常:NSInvalidArgumentException與FBSDKGraphRequest

終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',原因是: ' - [__ NSCFDictionary imagePathForPictureMode:大小:]:無法識別的選擇發送到實例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

主要是因爲圖形請求(如/ me)的結果不是FBSDKProfile。 –

+0

@MingLi我的不好!我認爲這是因爲代碼完成自動建議'imagePathForPictureMode' ...我嘗試過'FBSDKProfile.currenProfile()',但它總是似乎爲零。任何想法爲什麼? – doovers

+0

你有一個有效的訪問令牌嗎?在獲取訪問令牌之後,「currentProfile」是異步獲取的,因此根據何時請求當前配置文件,它可能爲零。您也可以在配置文件更新時觀察FBSDKProfileDidChangeNotification。請參閱https://developers.facebook.com/docs/reference/ios/current/class/FBSDKProfile/ –

回答

相關問題