Search code examples
iphonescheduled-tasksswift3ios10uidatepicker

How to trigger an action on specific date even if the app is closed?


I am trying to implement a scheduler function in my application using UIDatePicker and dateFormatter so that when a user select a date and time for the action to run on that specific date, the action should occur even if the app is closed, so how can I achieve same?


Solution

  • It is not possible to (guaranteed) run specific code at a certain time if your app is not running.

    It is possible to schedule a local NSNotification to inform the user. In case the user triggers your notification, your app is started / woken up by the OS and you can handle it. A nice notification guide can be found here