Nsurlerrordomain Error Code 1002 Description

I am new to iOS development. I am trying to load a JSON, here's my function:

func loadmyJSON (urlPath: String) {      

    let url: NSURL = NSURL(string: urlPath)!

    let session = NSURLSession.sharedSession()

    let task = session.dataTaskWithURL(url, completionHandler: {data, response, error -> Void in
               println("Task completed")
        if(error != nil) {
            // If there is an error in the web request, print it to the console
            println("error not nil::::::")
            println(error.localizedDescription)
        }
        var err: NSError?
        
        var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as NSDictionary
        if(err != nil) {
            // If there is an error parsing JSON, print it to the console
            println("JSON Error \(err!.localizedDescription)")
    }
    
        
        let results: NSArray = jsonResult["variants"] as NSArray
                    dispatch_async(dispatch_get_main_queue(), {
            
            self.jsonTable = results
            self.productView!.reloadData()
           })
     })

But I am getting this error:

error not nil::::::

The operation couldn’t be completed. (NSURLErrorDomain error -1002.)

I am able to get the JSON in the browser through the same URL. I have tried reading this Apple Doc, but I can't get the description.

What does this error code mean?

4

3 Answers

NSURLErrorDomain error -1002 means NSURLErrorUnsupportedURL or kCFURLErrorUnsupportedURL. It indicates that a bad URL was provided, in most cases, missing http:// from the URL prefix.

The list of all NSURLErrorDomain codes can be found here:

0

In addition to the above answer, one of the reasons why this could happen is,

You might have set the Allow Arbitrary Loads to false in your Info.plist and the URL you are trying to load is not on a secured server.

The solution to this is either set it to true, or move to a secure connection i.e https://.

Hope it helps someone. All the best.

I encounter the same issue and found that key parameter was missing from URL. You need to set Google map key value for key parameter in URL you are using to make request. This can be occur if you are missing other keys.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest