ios - How does one deal with a cancelled NSURLSessionTask in the completion handler block? -
if create nsurlsessiondownloadtask
, , later cancel before finishes, completion block still fires seemingly.
let downloadtask = session.downloadtaskwithurl(url, completionhandler: { location, response, error in ... }
how check whether or not download task cancelled within block don't seek operate on resulting download when there isn't one?
for download task, completion handler called nil
value location
, code
value of nserror
object nsurlerrorcancelled
.
let task = session.downloadtaskwithurl(url) { location, response, error in if error != nil { if error.code == nsurlerrorcancelled { // canceled } else { // other error } homecoming } // proceed move file @ `location` somewhere more permanent } task.resume()
likewise info tasks, completion handler called nil
value nsdata
object , nserror
object indicate canceled.
let task = session.datataskwithurl(url) { data, response, error in if error != nil { if error.code == nsurlerrorcancelled { // canceled } else { // other error } homecoming } // otherwise handler info here } task.resume()
ios cocoa-touch swift nsurlsession nsurlsessiondownloadtask
No comments:
Post a Comment