-1

I'm trying to fetch an image from parse which is similar to this problem

iOS - Retrieve and display an image from Parse in UIImageView (Swift 1.2 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")
            }
        })
    }
}

It keep returning nil

2
  • There are no returns in the code you show... Do you mean that the UIImage constructor returns nil? Commented Oct 28, 2015 at 12:51
  • @Animal the imageData it's returning nil Commented Oct 28, 2015 at 12:59

1 Answer 1

1

I think your error is due to App Transport Security. You are fetching an image from an unsafe http url and to do that you have to enable the url in your Info.plist file.

More about ATS

Basically what you can test is to disable ATS by adding

<key>NSAppTransportSecurity</key>
<dict>
  <!--Include to allow all connections (DANGER)-->
  <key>NSAllowsArbitraryLoads</key>
      <true/>
</dict>

to your Info.plist file. (right click Info.plist -> Open as -> source code, and add the key and value above.)

If this works you should add a special permission for this url only and revert the previous disabling.

To just enable the specific domain is a bit trickier. You need to know a little bit about what violates the ATS to fix it. It would look something like this I imagine

<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>
Sign up to request clarification or add additional context in comments.

1 Comment

it worked! thank you! could you please update your answer on adding a special permission of www.parse.com?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.