I m using ASIHTTP Request sample source code for downloading urls. My question is that how to pause and resume the downloading files.
Please Help.
I m using ASIHTTP Request sample source code for downloading urls. My question is that how to pause and resume the downloading files.
Please Help.
Deprecation Notice
ASIHTTP was deprecated around 2011, if you want network connectivity now, you should look up AFNetworking for ObjC or Alamofire for Swift, or stick to the native support:
For native support, in iOS 7 Apple added the
NSURLSession
, which can start download tasks (NSURLSessionDownloadTask
), and these can be cancelled and restarted, check the methoddownloadTaskWithResumeData(_:)
fromNSURLSession
, that has a very good explanation.ASIHTTP is no longer needed, if you gotta are keeping a legacy app running, well, good luck.
Original Answer
Posted on 2011
ASI itself can resume a download from a file using
[myASIRequest setAllowResumeForFileDownloads:YES];
, check out the How-to-Use for an example.Edit: Ok, there's no easy way to pause a download (a
[myRequest pause]
would be ideal). After reading and trying for a while, turns out that cancelling the request and resending it again is the only way.For example, here's an example class I made:
To start (or restart) the download:
In the exmaple above, I'm loading a random image of cheese I found, and storing a temporary download, and a full download.
Canceling the request will keep the contents of the temporary file intact, in fact, I made an UIImageView, and when pressing "Cancel" I could see a part of the downloaded file. If you want to try it out: