【问题标题】:Pulling Facebook profile pic with parse using Swift使用 Swift 通过解析提取 Facebook 个人资料图片
【发布时间】:2015-10-28 15:30:42
【问题描述】:

我正在尝试为我的应用个人资料页面提取用户名和个人资料图片。我正在使用 Parse 和 Facebook SDK。

我有一个 UILabel 和一个 UIView 作为插座连接。

当我尝试设置 profileImageView 时,它给了我错误 “'UIImageView' 类型的值没有成员 'setImageWithURL'” 这是 Swift 的升级吗?

这是我的代码...

func setProfilePicture() {
    FBSDKGraphRequest(graphPath: "me", parameters: nil).startWithCompletionHandler({ (connection, result, error) -> Void in
        if let dict = result as? Dictionary<String, AnyObject> {
            let name: String = dict["name"] as! String
            let facebookID: String = dict["id"] as! String

            let pictureUrl = "https://graph.facebook.com/\(facebookID)/picture?type=large&return_ssl_resources=1"

            self.profileImageView.setImageWithURL(NSURL(string: pictureUrl)!)
            self.nameLabel.text = name
            PFUser.currentUser()!.setValue(name, forKey: "name")
            PFUser.currentUser()!.saveInBackground()
        }
    })

}

【问题讨论】:

    标签: facebook swift parse-platform profile


    【解决方案1】:
    if let url = NSURL(string: "https://graph.facebook.com/\(facebookID)/picture?type=large&return_ssl_resources=1") {
        if let data = NSData(contentsOfURL: url){
            self.profileImageView.contentMode = UIViewContentMode.ScaleAspectFit
            self.profileImageView.image = UIImage(data: data)
        }
    }
    

    【讨论】:

      【解决方案2】:

      尝试创建一个函数fbProfilePicURL,它接受一个 Facebook ID 并将个人资料图片 URL 作为NSURL 返回,然后更改

      self.profileImageView.setImageWithURL(NSURL(string: pictureUrl)!)
      

      self.profileImageView.setImageWithURL(NSURL.fbProfilePicURL(facebookID))
      

      对此不是 100% 确定,但如果它有效,请告诉我。

      【讨论】:

      • 我应该补充一点,我在我的程序中使用了 cocoapods。我错过了 AFNetworking,所以我安装了它并添加了“import AFNetworking”。这让我可以访问“setImageWithURL”,现在一切正常!
      猜你喜欢
      • 2017-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-03
      • 1970-01-01
      • 1970-01-01
      • 2014-09-28
      • 2016-09-09
      相关资源
      最近更新 更多