Basic Background Task (Save on Suspend)
Goal
When the app is being suspended, start background allowance, save quickly, then end the task.
Actions used
TaskServicesStartTaskAndAllowInBackgroundTaskServicesCancelTask
Variables
taskId(String) (optional)
Flow
State:
OnApplicationPause(true)(or your “app suspending” trigger)Go to
StartBackgroundAllowance.
State:
StartBackgroundAllowanceAction:
TaskServicesStartTaskAndAllowInBackgroundSave
taskIdoutput (optional).Events:
startedEvent→DoSavefailureEvent→DoSave(fallback: still try a minimal save)
State:
DoSaveDo your save work (keep it short on iOS).
Then go to
EndBackgroundAllowance.
State:
EndBackgroundAllowanceAction:
TaskServicesCancelTaskInput:
taskId(or leave empty to useTaskServicesUtils.LastTaskId)
Notes
Assign
quotaWillExpireEventonTaskServicesStartTaskAndAllowInBackgroundand add it as a Global Transition if you need an emergency “save minimal” path (see Use Case 2).
Last updated
Was this helpful?