iOS - 在 UIImageView 中检索并显示来自 Parse 的图像(Swift 2.1 错误)
iOS - Retrieve and display an image from Parse in UIImageView (Swift 2.1 Error)
我正在尝试从解析中获取与此问题类似的图像
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")
}
})
}
}
它一直返回 nil
我认为您的错误是由于 App Transport Security 造成的。您正在从不安全的 http url 获取图像,为此您必须在 Info.plist 文件中启用 url。
基本上你可以测试的是通过添加
来禁用 ATS
<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections (DANGER)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
到您的 Info.plist 文件。 (右击Info.plist -> 打开方式 -> 源代码,添加上面的key和value。)
如果可行,您应该只为此 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>
我正在尝试从解析中获取与此问题类似的图像
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")
}
})
}
}
它一直返回 nil
我认为您的错误是由于 App Transport Security 造成的。您正在从不安全的 http url 获取图像,为此您必须在 Info.plist 文件中启用 url。
基本上你可以测试的是通过添加
来禁用 ATS<key>NSAppTransportSecurity</key>
<dict>
<!--Include to allow all connections (DANGER)-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
到您的 Info.plist 文件。 (右击Info.plist -> 打开方式 -> 源代码,添加上面的key和value。)
如果可行,您应该只为此 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>