简体   繁体   中英

Swift can't retrieve images from parse.com

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.

I'm getting username on table view but the images not showing I get this error when testing on simulator 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.

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

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 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>

Should look like this 在此处输入图片说明

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

Your second issue is explain below

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 
}

Apple is now forcing HTTPS connections, that is the App Transport Security message. You are still sending over clear text HTTP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM