-1

我正在尝试从类似于此问题的解析中获取图像

iOS - 在 UIImageView 中从 Parse 检索并显示图像(Swift 1.2 错误)

func fetchDataEmployer(){

    self.companyNameLabel.text = (PFUser.currentUser()?.objectForKey("companyName")?.capitalizedString)! as String

    //MARK: - FETCHING IMAGE FILE FROM PARSE
    if let companyImage = PFUser.currentUser()?["profileImageEmployer"] as? PFFile {
        companyImage.getDataInBackgroundWithBlock({ ( imageData: NSData?, error: NSError?) -> Void in
            if error == nil{
                self.profileEmployerImage.image = UIImage(data: imageData!)
            } else {
                print("No image found")
            }
        })
    }
}

它一直返回零

4

1 回答 1

1

我认为您的错误是由于应用程序传输安全性造成的。您正在从不安全的 http url 获取图像,为此您必须在 Info.plist 文件中启用该 url。

更多关于 ATS

基本上你可以测试的是通过添加禁用 ATS

<key>NSAppTransportSecurity</key>
<dict>
  <!--Include to allow all connections (DANGER)-->
  <key>NSAllowsArbitraryLoads</key>
      <true/>
</dict>

到您的 Info.plist 文件。(右键Info.plist -> Open as -> source code,并添加上面的键和值。)

如果这可行,您应该只为这个 url 添加一个特殊权限并恢复以前的禁用。

仅启用特定域有点棘手。您需要了解一些违反 ATS 的内容才能修复它。它看起来像我想象的这样

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>parse.com</key>
    <dict>
      <!--Include to allow subdomains-->
      <key>NSIncludesSubdomains</key>
      <true/>
      <!--Include to allow HTTP requests-->
      <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
      <true/>
      <!--Include to specify minimum TLS version-->
      <key>NSTemporaryExceptionMinimumTLSVersion</key>
      <string>TLSv1.1</string>
    </dict>
  </dict>
</dict>
于 2015-10-28T13:56:21.980 回答