Ho cercato ma non ho trovato una risposta pertinente solo nell'obiettivo C. C'è un modo per trovare l'avanzamento del download di un file in Swift, in modo da mostrarlo per utente? Sono nuovo alla programmazione iOS e ho provato con NSURLSession ma senza successo.Trova lo stato di avanzamento di un file in swift
EDIT: Ho usato questo metodo come visto in this post, ma io non riesco a capire come ottenere lo stato di avanzamento:
func downloadFile(page: NSString){
finished = false
var statusCode:Int = 0
println("Download starting")
let url = NSURL(string: page)
let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data, response, error) in
if error != nil {
println("download failed with error \(error?.localizedDescription)")
} else {
println("Expected Content-Length \(response.expectedContentLength)")
self.contentLength = response.expectedContentLength
if let httpResponse = response as? NSHTTPURLResponse {
println("Status Code of number \(self.countDownload) is \(httpResponse.statusCode)")
statusCode = httpResponse.statusCode
}
}
}
task.resume()
}
Grazie in anticipo
Come hai provato questo con 'NSURLSession' e cosa ha fatto di sbagliato? – Wain
Mostraci cosa hai provato – ColdSteel