- 后台传输时,需要保证队列里有多于一个任务,否则程序仍然会挂起。
- 后台传输服务仅支持
NSURLSessionUploadTask
,NSURLSessionDownloadTask
,并不支持NSURLSessionTask
。 - 后台上传时,只能使用
uploadTaskWithRequest:fromFile:
这个方法。如果NSURLSession对象由backgroundSessionConfiguration
这个参数创建,这个方法uploadTaskWithRequest:fromData:
不会工作。参见这里 - In iOS, when a background transfer completes or requires credentials, if your app is no longer running, iOS automatically relaunches your app in the background and calls the
application:handleEventsForBackgroundURLSession:completionHandler:
method on your app’sUIApplicationDelegate
object. This call provides the identifier of the session that caused your app to be launched. Your app should store that completion handler, create a background configuration object with the same identifier, and create a session with that configuration object. The new session is automatically reassociated with ongoing background activity. Later, when the session finishes the last background download task, it sends the session delegate aURLSessionDidFinishEventsForBackgroundURLSession:
message. Your session delegate should then call the stored completion handler.