Is there anyway to keep a timer running after the application is terminated (not in background). I want to do this so a local notification is triggered once the timer reaches 0.
Can UserDefaults be used to achieve this?
Is there anyway to keep a timer running after the application is terminated (not in background). I want to do this so a local notification is triggered once the timer reaches 0.
Can UserDefaults be used to achieve this?
Guessing you are talking about iOS, have a look at this: https://developer.apple.com/library/ios/documentation/iphone/Reference/UILocalNotification_Class/Reference/Reference.html
NSTimer is not what you looking for, since it's only working at the runtime of your App. UILocalNotification let you create a notification (including scheduling it for s specific time) handled independently by the system.
NSTimer
cannot run infinitely in background. NSTimer
is paused when your application enters background.
You have to use repeatInterval
property of UILocalNotification
to achieve it.
UILocalNotification *alarm = [[UILocalNotification alloc] init];
alarm.fireDate = [NSDate date];
alarm.timeZone = [NSTimeZone localTimeZone];
alarm.repeatInterval = NSMonthCalendarUnit;
[app scheduleLocalNotification:alarm];