Hello,
I created a radio application that sources its data from a JSON file found on the internet. The logic behind this is that, if i need to make some changes to the data i want included in the app, i just need to edit that file and it will work. However I noticed that once i make changes to the JSON data the changes are seen in the simulators but not on devices that already have installed my app. I confirm this by deleting and re-installing the app on my phone. Once i did this the new data was there.
Is there a reason to this?
Could i just release a new version with no code changes? Although this defeats the purpose of hosting the JSON online.
Take a look at my code for loading JSON data from URL:
static func loadDataFromURL(url: URL, completion: @escaping (_ data: Data?, _ error: Error?) -> Void) {
let sessionConfig = URLSessionConfiguration.default
sessionConfig.allowsCellularAccess = true
sessionConfig.timeoutIntervalForRequest = 15
sessionConfig.timeoutIntervalForResource = 30
sessionConfig.httpMaximumConnectionsPerHost = 1
let session = URLSession(configuration: sessionConfig)
// Use URLSession to get data from an NSURL
let loadDataTask = session.dataTask(with: url) { data, response, error in
guard error == nil else {
completion(nil, error!)
if kDebugLog { print("API ERROR: \(error!)") }
return
}
guard let httpResponse = response as? HTTPURLResponse, 200...299 ~= httpResponse.statusCode else {
completion(nil, nil)
if kDebugLog { print("API: HTTP status code has unexpected value") }
return
}
guard let data = data else {
completion(nil, nil)
if kDebugLog { print("API: No data received") }
return
}
// Success, return data
completion(data, nil)
}
loadDataTask.resume()
}