I am trying to read an online JSON file using the sample found here. It seems quite straight forward except when I run it. It keeps failing at dataTaskWithURL call and the error.localizedDescription is "The operation couldn't be completed. (NSURLErrorDomain -1005.)" I have looked up the error code and it refers to NSURLErrorNetworkConnectionLost but I am connected to internet and when I try the same url in a browser, I receive the JSON result.
func searchItunes() {
let urlPath = "http://itunes.apple.com/search?term=JQ+Software&media=software"
let url: NSURL = NSURL(string: urlPath)
let session = NSURLSession.sharedSession()
let task = session.dataTaskWithURL(url, completionHandler: {
data, response, error in
if(error != nil) {
println(error.localizedDescription)
}
else {
var err: NSError?
var jsonResult = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: &err) as NSDictionary
if(err != nil) {
println("JSON Error \(err!.localizedDescription)")
}
else {
// process data here.
}
}
})
task.resume()
}