Swift无法从parse.com检索图像 [英] Swift can't retrieve images from parse.com

查看:74
本文介绍了Swift无法从parse.com检索图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Xcode 6.4,它工作正常,但是当我更新到Xcode 7时,似乎查询不适用于照片.

I was using 6.4 of Xcode and it was working fine but when I updated to Xcode 7 it seems like query isn't working for photos.

我在表视图上获取用户名,但未显示图像,但在模拟器iPhone 5上进行测试时出现此错误:

I'm getting username on table view but the images not showing I get this error when testing on simulator iPhone 5:

由于应用传输安全性不安全,因此它阻止了明文HTTP(http://)资源加载.可以通过您应用的Info.plist文件配置临时例外.

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上进行测试时,出现此错误:

And when I test it on iPhone 6 I got this error :

严重错误:解开可选值时意外发现nil
(lldb)

fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb)

并在此行上向我显示一个红色线程:

and showing me a red thread on this line :

query.whereKey("user", equalTo: PFUser.currentUser()!.username!) 

推荐答案

Apple现在强制开发人员使用ATS(HTTPS),但是您可以通过添加此功能在info.plist中将其禁用

Apple now forcing dev to use ATS(HTTPS), but you can disable it in info.plist by adding this

<key>NSAppTransportSecurity</key>  
     <dict>  
          <key>NSAllowsArbitraryLoads</key><true/>  
     </dict>

应如下所示:

访问 Apple文档有关ATS的更多详细信息,请观看此 WWDC视频会话

Visit Apple docs for more details about ATS and please watch this WWDC video session

您的第二个问题在下面说明

Your second issue is explain below

FPUser.currentUser可以返回nil,并且您正在使用!强制展开,然后使用calling username,因此,如果用户未登录,则currentUser将返回nil,您最终将调用<nil上的c4>,因此您将发生此崩溃,应该执行以下操作.

FPUser.currentUser can return nil if user logged out, and you are using ! force unwrapping and then calling username, so if user is not logged in then currentUser will return nil and you will end up calling username on nil, hence you are getting this crash, you should do something like this.

if let user = PFUser.currentUser()
{
   query.whereKey("user", equalTo: user.username!) 
}
else
{
   // show login ui 
}

这篇关于Swift无法从parse.com检索图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆