- iOS 7.0+
- macOS 10.9+
- tvOS 9.0+
- watchOS 2.0+
Download tasks directly write the server’s response data to a temporary file, providing your app with progress updates as data arrives from the server. When you use download tasks in background sessions, these downloads continue even when your app is suspended or is otherwise not running.
You can pause (cancel) download tasks and resume them later (assuming the server supports doing so). You can also resume downloads that failed because of network connectivity problems.
When you use download tasks:
During download, the session periodically calls the delegate’s
URLSession:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:method with status information.
Upon successful completion, the session calls the delegate’s
URLSession:downloadTask:didFinishDownloadingToURL:method or completion handler. In that method, you must either open the file for reading or move it to a permanent location in your app’s sandbox container directory.
Upon unsuccessful completion, the session calls the delegate’s
URLSession:task:didCompleteWithError:method or completion handler. Unlike
NSURLSessionDownloadTaskreports server-side errors reported through HTTP status codes into corresponding