My app uses a repeating 24 hour DeviceActivitySchedule defined like this:
let intervalStart = DateComponents(hour: 0, minute: 0, second: 0)
let intervalEnd = DateComponents(hour: 23, minute: 59, second: 59)
let schedule = DeviceActivitySchedule(
intervalStart: intervalStart,
intervalEnd: intervalEnd,
repeats: true)
try center.startMonitoring(
ACTIVITY_NAME,
during: schedule,
events: [...])
Both intervalDidStart
and intervalDidEnd
callback functions update CoreData and UserDefaults, and sometimes make network requests, and I'm worried that their close invocations may cause unexpected behavior.
Since intervalDidStart
should be invoked only one second after intervalDidEnd
, but intervalDidEnd
may take longer than one second to run, due to updating local data and waiting for network requests to complete, how should this effect the invocation time of intervalDidStart
? Is there a rule about the ordering of these functions, for instance if the interval is repeating and essentially overlaps like mine, is it guaranteed that intervalDidStart
will always be called after intervalDidEnd
returns, or is the behavior more undefined?