Situation: App has several huge files to upload to a server. User starts upload in foreground, get tired watching the slow progress, and backgrounds the app do web surf.
I've been looking at "tus" (resumable uploads) and coming up with all kinds of crazy schemes, and sitting back and rethinking this, I'm now wondering if I have overcomplicated the solution.
What appears now to be the simple and easiest solution is to create a background URL Session while in the foreground, set "isDiscretionary" to false (want uploads to start immediately), then create some upload tasks and using the session delegate, watch the progress.
If the app backgrounds, then iOS will continue them with "isDiscretionary" still true (subject to internal constraints). Obviously no more progress delegate calls (no delegate!)
When upload tasks finished, the system will message me. I can even add more tasks at that point if I want.
If the task comes back into the foreground during the upload, I can reconstitute the session config, add myself back as a delegate and then I'll start seeing the delegate session messages again.
The above may sound simple and self apparent, but really, I've read many articles on using background sessions and haven't seen the use case of initiating them in the foreground and having the app switch back and forth between foreground and background.
Would really appreciate knowing if what I postulated above is correct or not.
As an aside, I was going to use the "tus" Concatenation API, break the big file into chunks, start sending the chunks in foreground, if moved to the back, cancel any partial uploads, then re-submit uploads to a background task. Complex and if the above works, totally unneeded.
David
I've been looking at "tus" (resumable uploads) and coming up with all kinds of crazy schemes, and sitting back and rethinking this, I'm now wondering if I have overcomplicated the solution.
What appears now to be the simple and easiest solution is to create a background URL Session while in the foreground, set "isDiscretionary" to false (want uploads to start immediately), then create some upload tasks and using the session delegate, watch the progress.
If the app backgrounds, then iOS will continue them with "isDiscretionary" still true (subject to internal constraints). Obviously no more progress delegate calls (no delegate!)
When upload tasks finished, the system will message me. I can even add more tasks at that point if I want.
If the task comes back into the foreground during the upload, I can reconstitute the session config, add myself back as a delegate and then I'll start seeing the delegate session messages again.
The above may sound simple and self apparent, but really, I've read many articles on using background sessions and haven't seen the use case of initiating them in the foreground and having the app switch back and forth between foreground and background.
Would really appreciate knowing if what I postulated above is correct or not.
As an aside, I was going to use the "tus" Concatenation API, break the big file into chunks, start sending the chunks in foreground, if moved to the back, cancel any partial uploads, then re-submit uploads to a background task. Complex and if the above works, totally unneeded.
David