Unable to sustain a Constant Speed while Uploading files in the background with NSURLSession

前端 未结 1 2019
执笔经年
执笔经年 2020-12-15 02:30

I am trying to upload some 100 images to S3 in the background with AFURLSessionManager in small batches of 10 like what is being done here- Manage the number of active tasks

相关标签:
1条回答
  • 2020-12-15 02:55

    From what I can tell, setTaskDidCompleteBlock: is not an Apple API, NSURLSession-associated method. It is an AFURLSessionManager method (docs). If you are using AFNetworking on this, then you need to be announcing that bold, top, front and center. That is not the same, at all, as using NSURLSession. I would guess AFNetworking's background NSURLSession-based implementation comes with its own foibles and idiosyncrasies.

    For my part, whatever success I've had with sustained background NSURLSession uploads are using only the stock API.


    Addressing questions, etc.

    • Regarding AFNetworking: we use it for general web api I/O. At the time NSURLSession came out, AFNetworking really didn't robustly support app-in-background ops, so I didn't use it. Perhaps because I went through the background NSURLSession pain & hazing, I look askance at AFNetworking backgrounding under the rubric of "Now you have two problems". But maybe they have cracked the nut by now.

      • I strive for one NSURLSession. I started out being cavalier about creation & destruction of sessions, but found this made for some truly gnarly problems. Experiences seem to vary on this.

      • I use the default HTTPMaximumConnectionsPerHost, no problems there. The Apple docs are silent on the default value, but here's what lldb tells me in the random particular device/OS I chose:
        (lldb) p [config HTTPMaximumConnectionsPerHost] (NSInteger) $0 = 4
        If you are having troubles with backgrounding slowing down, I doubt tweaking this is on the right track.

      • FWIW, background NSURLSessions do not support the block interfaces, delegate only.

    0 讨论(0)
提交回复
热议问题