Upload Completion (Finish or Defer)
Goal
When the app is suspending and an upload is pending, try to finish quickly; if time is about to expire, save-for-retry.
Actions used
TaskServicesStartTaskAndAllowInBackgroundTaskServicesCancelTask
Flow
When
uploadPending == trueand app is suspending:Start background allowance (
TaskServicesStartTaskAndAllowInBackground)Do the upload in the next state.
On success/failure, call
TaskServicesCancelTaskand clear/set your pending flags.
If
quotaWillExpireEventfires:Cancel/stop the upload work if possible.
Save the payload locally and set a “retry on next launch” flag.
Call
TaskServicesCancelTask.
Notes
Keep the upload small and bounded; don’t rely on long background time.
Assign
quotaWillExpireEventonTaskServicesStartTaskAndAllowInBackgroundand add it as a Global Transition to your “SaveForRetryNow” state.
Last updated
Was this helpful?