I've created a button when it is clicked, my app starts to download a json database which is stored in arrays.
When I start to download the database sometimes the internet is very slow and the device is not able to download the content, and the users can still use the app even though they didn't get the data they need.
What I want is a timer or a counter, which alerts the user when the request time exceeds 1 minute, and displays a message saying "No internet connection" or "Too slow to download the database".
I'd like you to give me at least an idea, because I don't even know what to search :(
thank you!
UPDATE: This is the code that I've got so far.
override func viewDidLoad() { super.viewDidLoad()
let url = NSURL(string: "http://146.83.128.64/tongoy/g.php?&sala=-1&curso=-1&profesor=-1&semestre=-1&semestrec=-1&carrera=-1&area=-1")!
let task = NSURLSession.sharedSession().dataTaskWithURL(url) { (data, response, error) -> Void in
if let urlContent = data {
do {
let jsonResult = try NSJSONSerialization.JSONObjectWithData(urlContent, options: NSJSONReadingOptions.MutableContainers)
for json in jsonResult as! Array<AnyObject> {
if let area = json["area"] as? String {
self.arregloArea.append(area)
}
if let id = json["id"] as? Int {
self.arregloID.append(id)
}
if let curso = json["curso"] as? String {
self.arregloCursos.append(curso)
}
if let carreras = json["carreras"] as? Array<AnyObject> {
for item in carreras {
if let id = item["id"] as? Int {
print(id)
}
if let nombre = item["nombre"] as? String {
print(nombre)
}
if let semestre = item["semestre"] as? Int {
print(semestre)
}
if let curso = item["curso"] as? Int {
print(curso)
}
}
}
}
} catch {
print("JSON serialization failed")
}
dump(arregloCursos)
dump(arregloArea)
dump(arregloID)
}
}
task.resume()
}