I am attempting to arrange background HTTP add requests (syncing information from the consumer’s telephone to a server) that set off periodically in my Swift app. I haven’t got strict necessities on when this runs (it could occur in a single day or all through the day).
I do know Apple gives a number of APIs for background duties on iOS (beginBackgroundTask
, BGAppRefreshTaskRequest
, BGProcessingTaskRequest
, URLSession
add vs. background session). And I’ve seen this publish on the Apple developer boards that makes an attempt to elucidate the variations and when to make use of which – in addition to Apple’s web page on the topic, nevertheless it’s nonetheless not clear to me how a couple of of those work in apply, and thus which of them I ought to make the most of for my use case.
My questions:
- How ought to I schedule periodic file add duties within the background?
- I assume I ought to use
BGProcessingTaskRequest
, since I do not know precisely how lengthy the duty will take (it could possibly be syncing simply 1-2 information, or it could possibly be a whole lot) and I do not care if it runs in a single day
- I assume I ought to use
- How ought to I guarantee foreground duties are capable of full after closing the app? (i.e. when a consumer begins a sync manually within the app)
- From Apple’s web page on
URLSessionUploadTask
: “In contrast to knowledge duties, you should use add duties to add content material within the background.”- Does this imply any requests I make utilizing
URLSession.shared.add()
will mechanically run within the background if the consumer closes the app? Even with the async/await model, or do I’ve to make use of thecompletionHandler
model?
- Does this imply any requests I make utilizing
- Do I must name
beginBackgroundTask
if I am utilizingURLSession.shared.add()
to ensure I get extra time to complete uploads? - What about sequential requests (i.e. requests that have not began but by the point the app is closed)? Primarily based on this SO response, it feels like I could must set off all of the uploads in parallel beforehand? https://stackoverflow.com/a/53949607/2359478
- From Apple’s web page on
- Ought to I even contemplate
URLSessionConfiguration.background
for my use case? It sounds prefer it I exploitbeginBackgroundTask
andBGProcessingTaskRequest
then this can be pointless?
Thanks!