downloadTaskWithRequest confusing behaviour (swift , IOS ) -
i not understand following , hope :-)
i downloading file url (10 minutes downloadtime), works fine, when download completes.
but: when simulate crash or internet-interruption after minute , restart app again, behaves strange me. in case when restarting app download again same sessionid, seems 2 download tasks working in parallel. recognizue jumping progressbar 10% 0% , back. one, starts scratch , one, guess continious old transfer. (not sure). can restart again , there 1 more in queue.
can confirm behaviour , know how can: - continue interrupted download task (preferred :-) ) - or how can start scratch only.
here code downloading, works fine without interruption.
func download_file(surl: string, stolocation: string) { println("start downloading ..."); println("surl : " + surl + " stolocation : " + stolocation); bytesdownloaded=0; var delegate = self; delegate.storepath=stolocation; delegate.progressview=progressview; struct sessionproperties { static let identifier : string! = "url_session_background_download" } var configuration = nsurlsessionconfiguration.backgroundsessionconfigurationwithidentifier(sessionproperties.identifier) var backgroundsession = nsurlsession(configuration: configuration, delegate: delegate, delegatequeue: nil) //myurlsession = nsurlsession(configuration: configuration, delegate: delegate, delegatequeue: nil) var url = nsurlrequest(url: nsurl(string: surl)!) var downloadtask = backgroundsession.downloadtaskwithrequest(url) //downloadtask.cancel() downloadtask.resume() }
update when using different sessionid, download starts scratch. started download task runs still in background. wondering why can't resume download task using old sessionid without starting new download in parallel ?
the whole point of using download task downloads can continue if app isn't running or if crashes. don't need resume download. happening in separate background daemon. need re-create session using same id.
after re-create session, existing downloads automatically associated new session, , delegate methods called whenever task completes.
there's little bit of magic need implement handling background launches if app isn't running when download finishes. see url session programming guide details.
Comments
Post a Comment