'How can I set my app information and process power active even it gets closed or killed

Here is a simple code for reminding something to user with this code:

func alarmFunction() {
    DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + .seconds(120)) {
        print("user custom Alarm!")
    }
}

As you can see the user want an alarm after 2 min from now, this code works fine if the app is alive, but if the app got accidentally killed, user would miss out the needed alarm that he set up. How can I make my code for alarmFunction() stay in memory of device, even if the app got killed? almost same situation that apple alarm works, even if we close alarm.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source