我使用的是 6.4 的 Xcode,它工作正常,但是当我更新到 Xcode 7 时,它似乎无法查询照片。
我在表格 View 中获取用户名,但图像未显示我在模拟器 iPhone 5 上测试时遇到此错误:
App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
当我在 iPhone 6 上测试它时,我得到了这个错误:
fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb)
并在这一行显示一条红线:
query.whereKey("user", equalTo: PFUser.currentUser()!.username!)
最佳答案
Apple 现在强制开发人员使用 ATS(HTTPS),但您可以通过在 info.plist 中添加它来禁用它
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key><true/>
</dict>
访问Apple docs有关 ATS 的更多详细信息,请观看此 WWDC video session
你的第二个问题在下面解释
如果用户注销,FPUser.currentUser
可以返回 nil,并且您正在使用 !
强制解包然后 调用用户名
,所以如果用户未登录然后 currentUser
将返回 nil,您最终将在 nil
上调用 username
,因此您会遇到此崩溃,您应该这样做像这样。
if let user = PFUser.currentUser()
{
query.whereKey("user", equalTo: user.username!)
}
else
{
// show login ui
}
关于ios - Swift 无法从 parse.com 检索图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32038667/