I'm using the new NSURLSession API and allowing the user to download files. I'd like to try and tell my NSURLSession how many simultaneous downloads to run, but I don't see a way to do it. I'd like to try to avoid managing the download tasks myself, would be much better if I could tell the system how many to allow instead - that would be better for queuing background downloads as well when my app isn't running. Is there a way to do this?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Attempt to present UIAlertController on View Contr
I found a workaround for this timeouts.
Tried to download a file with slow connection simulation on device(Settings -> Developer -> Network link conditioner -> Choose a profile -> 3G -> Enable).
Here is my sample code:
And my output:
As you can see tasks started time out after 2 minutes
I played with
timeoutIntervalForResource
and timeoutIntervalForRequest parameters and in case we set both to 0 it will downloads without timeouts. But I think it isn't a good idea because of battery drawn. I think that 10 minutes or something like it will be a good value for it. But you have to set both parameters to the same value.Apple docs:
Noticed strange thing: in case we set
timeoutIntervalForResource = 60
andtimeoutIntervalForRequest = 30
, tasks will time out after 30 seconds! But most of them won't even start!Looks like timer for
timeoutIntervalForRequest
started when task resumed. In that case we resumed all tasks in the same time and each task's timeout has to be as a resource timeout.Also, I can advise wwdc13 705 session with a great demo about background session with download task.
You can set it in the
NSURLSessionConfiguration
object with theHTTPMaximumConnectionsPerHost
property.