I have some business requirements to send data to a particular cloud location while the app is not running (not even in the background). I am looking for Apple support on whether there are any services in iOS SDK which allow me to do the same. This service should continue to upload data until it detects that there is no more data left to be uploaded.
Upload files while app is not running or terminated
The only API that can transfer data across the network while your app is run running (either suspended in the background or terminated) is URLSession
, and specifically its background session support.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
Will URLSession start automatically? Here I want my app to start uploading data automatically. Let's say my app created few files while there was not internet. As there was no internet, app could not upload these files and these files were saved to the device. Now App is terminated. After some time device had access to internet. So here I would like my application to start uploading these files to server. Is it possible in iOS?
Let's say my app created few files while there was not internet. As there was no internet, app could not upload these files and these files were saved to the device.
That should be feasible. If you start an upload task in a background session while the network is unavailable, the URLSession
background session will hold on to the task waiting for conditions to improve. At some point it will start the upload on your behalf, without your app having to do anything.
One thing to be aware of here is that is that it does not guarantee to start the upload as soon as the device has access to the network. In many cases it will defer the upload until that night, when the device has both network access and is on mains power.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
Wouldn't that session get timed out?
URLSession
tasks time out based on two values:
-
timeoutIntervalForRequest
, which is the timeout that applies while the task is active on the wire -
timeoutIntervalForResource
, which is the overall timeout for the task
The default value for the latter is 7 days so, no, it’s unlikely to time out.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"