Basic Background Task (Save on Suspend)
Last updated
When the app is being suspended, start background allowance, save quickly, then end the task.
TaskServicesStartTaskAndAllowInBackground
TaskServicesCancelTask
taskId (String) (optional)
State: OnApplicationPause(true) (or your “app suspending” trigger)
Go to StartBackgroundAllowance.
State: StartBackgroundAllowance
Action: TaskServicesStartTaskAndAllowInBackground
Save taskId output (optional).
Events:
startedEvent → DoSave
failureEvent → DoSave (fallback: still try a minimal save)
State: DoSave
Do your save work (keep it short on iOS).
Then go to EndBackgroundAllowance.
State: EndBackgroundAllowance
Action: TaskServicesCancelTask
Input: taskId (or leave empty to use TaskServicesUtils.LastTaskId)
Assign quotaWillExpireEvent on TaskServicesStartTaskAndAllowInBackground and add it as a Global Transition if you need an emergency “save minimal” path (see Use Case 2).
Last updated