I am working on an app which uses iOS NSURLSession background session to upload the data to the S3 server. From iOS 15.x
, We have observed that transfer speed has become too slow (~10 kbps).
Following is the configuration, I am using
NSURLSessionConfiguration
using backgroundSessionConfigurationWithIdentifier8
60s
86400s
(1 Day)false
tls_protocol_version_TLSv12
NSURLSession
using sessionWithConfigurationWhen I tested with iPadOs 14.8.1
, there is no degradation in performance, but with iPadOs 15.3.1
and 15.5
, I can see the performance degradation (uploads getting 6x slow).
When I create the session using ephemeralSessionConfiguration upload is very fast and there is no degradation (working as before).
For all the tests, I am keeping the app in foreground only.
I have few queries:
15.x
and greater ?iOS
) to schedule the requests and we (clients) has no or very little control over the transfer speeds ?PS: The degradation is happening with iOS simulators also. In case of simulators, somehow it is dependent on macOs versions (as seen from my tests).
On macOs 12.4
, in xCode 13.2
, iOS 12.x
, 13.x
, 14.x
, 15.x
simulators are showing the performance degradation.
When the same app is compiled from macOs 11.4
, xCode 12.4
, iOS 12.x
, 13.x
, 14.x
are not showing any performance degradation.
Any inputs would be highly appreciated.
Having struggled with this problem myself, I wanted to share the solution - for others, and also for future me when I run into this again and inevitably forget: to fix slow download speeds for uploads using a background session configuration, make sure you configure the request's network service type - this setting works for me:
var request = URLRequest(...)
// configure request
request.networkServiceType = .responsiveData
.responsiveAV
also worked for me. Do make sure you are only setting this if it is important that uploads happen in a timely manner - if it isn't important just hand it off to the background session with an appropriately configured timeout and let it get on with it.
Note: this will only have an impact if the upload task is started while the app in the foreground. If the upload task begins when the app is already in the background (for example, you need to do some other work first with some extended background execution time and then resume the upload task) then it will ignore this and behave as if you had set it to .background
which will be as slow as before as requests started in the background are heavily throttled.