1

At an earlier point today, I was able to use this API and get a response in my iPhone app. The fact that I have been trying to debug this for so long is making be believe that I'm crazy! Attached is a screenshot of my console...

enter image description here

Here is my code pertaining to my API call. Using Apple's URLSession and following many stack overflow questions / Tutorials I can not get this thing to work.

 let task = URLSession.shared.dataTask(with: request) { data, response, error in
        guard let data = data else {
            print("request failed \(error)")
            return
        }
        do {
            if let json = try JSONSerialization.jsonObject(with: data) as? [String: String], let result = json["result"] {
                // Parse JSON
            }
        } catch let parseError {
            print("parsing error: \(parseError)")
            let responseString = String(data: data, encoding: .utf8)
            print("raw response: \(responseString)")
        }
    }
    task.resume()

Every time I get this interesting [BoringSSL] Error and the searching I've done regarding that has not produced effective in fixing whatever bug I have.

Like I said, earlier today I had this app working using the same API. I have tried the key that the website gave me and the test key they use on their site. Now that I think of it, I am going to use the exact URL from my code and the screenshot and take a screenshot from the response I get in my browser. See below:

enter image description here

Received above response with the exact URL being used in my app.

4
  • Does this help forums.developer.apple.com/thread/92455 ? Commented Feb 9, 2018 at 6:36
  • According to your last screenshot, you don't have a data structure indicated by '[String: String].' Commented Feb 9, 2018 at 6:37
  • what is appendToBase var? Commented Feb 9, 2018 at 7:08
  • it is working for me can you tell what is the value coming for data... zipcodeapi.com/rest/… Commented Feb 9, 2018 at 7:32

2 Answers 2

3

tried your API in my project. It worked. You can check the difference below:

let urlTest = URL(string: "https://www.zipcodeapi.com/rest/wvyR5aWjHNUF80Z6kmr1bTuNojfzhmvtcmfBD8QNo9qbNAHy9FvBISINKF3W5i9J/multi-distance.json/99501/99501,%2085001,%2072201/km")

var request = URLRequest(url: urlTest!)

request.httpMethod = "GET"
let session = URLSession(configuration: .default)

let task : URLSessionDataTask = session.dataTask(with: request) { (data, response, error) in

        let statusCode = (response as! HTTPURLResponse).statusCode
        if statusCode == 200{
            do {
                let json = try JSON(data:data!)
            }
            catch {
                print("Could not convert JSON data into a dictionary.")
            }
        }
    }
    task.resume()

Printing description of json: ▿ { "distances" : { "85001" : 4093.922, "72201" : 4962.6189999999997 } }

Sign up to request clarification or add additional context in comments.

4 Comments

What import statements are required for JSON() ? I get an "Unresolved identifier 'JSON' " Error when compiling
it's swifty json
import SwiftyJSON
It is just for convenience. To get readable data from the response.
1

May be you have to turn off Transport Layer Security, because that worked for me.

Go to your info.plist file and add a property named App Transport Secrity Settings and set its Allow Arbitrary loads option to NO

Hope this helps.

Comments

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.