ios - Swift 无法从 parse.com 检索图像

标签 ios xcode swift parse-platform xcode7

我使用的是 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>

应该看起来像这样 enter image description here

访问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/

相关文章:

swift - Audiokit pod 出现重复符号

iphone - 将数组的内容写入文本文件

iphone - XCode 运行配置文件/检查器的配置配置文件无效 - iPhone 应用程序

ios - 使用多个分段控件管理 UITableView

ios - 如何在XMPP中接受好友请求?

uitableview - 表格单元格快速显示 NSMutableArray 的第一个索引数据

objective-c - armv7s 可执行文件大小增加

javascript - ionic : Keyboard overlaps a focused text input on iOS 11

ios - 如何在响应用户交互时运行 NSTimer 或重复的预定进程

iphone - 如何确定调用 moveItemAtURL :toURL: or replaceItemAtURL:WithItemAtURL: 时需要多少时间