iOS: OperationQueue.schedule(after: Date) that cannot be triggered by date change

413 views Asked by At

Problem

I need to get a callback when at least X amount of time has passed since the date for the callback has been set.

Example 1: This would have worked great, but it's possible to trigger an execution of the block by setting the date earlier than the correct time right now:

let responseDate = Date().advanced(by: 60) // 1 min
OperationQueue.current.schedule(after: .init(responseDate), {
print("the time is now!") // possible to set the current date 1 min before
}

On the other hand, the solution for getting a current uptime from this answer works great, but it requires timer constantly running to check if we're close to date.

Is it possible to combine these two approaches and somehow "attach" a callback to KERN_BOOTTIME, so that the OS will call my method when the boottime reaches a certain value?

I'm looking as well to alternative engineering solutions that satisfy two criterias:

  1. It should not be possible to trigger the callback by resetting the device date to some arbitrary value in the past
  2. If the device has been put to sleep (e.g. by pressing the on/off side button), the clock should still be "ticking", so that the method will be called back while the app is running in the background.

More details:

  • Backgrounding / app termination is out of scope
  • The main point is to prevent a bypass by switching the date backwards in the settings.
0

There are 0 answers