Reputation: 2237
I am making an app in iOS where it will send local notifications on a timer. It works fine when the app is in background state, but does not work when it has been terminated and closed completely.
Is there anyway to still send local notifications when this has happened?
Thanks in advance.
Upvotes: 10
Views: 10747
Reputation: 22701
The local notification can be delivered when the app is terminated or closed, but they must be scheduled when the app is running. You can set the fireDate
for a notification in the future, schedule it, and it will be delivered whether or not the app is running.
Upvotes: 4
Reputation: 325
Sure it is possible, if you schedule a local notification it will fire even if you terminate the app.
UILocalNotification *_localNotification = [[UILocalNotification alloc] init];
_localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:_value];
_localNotification.timeZone = [NSTimeZone defaultTimeZone];
_localNotification.alertBody = @"Beep... Beep... Beep...";
_localNotification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication]scheduleLocalNotification:_localNotification];
... works like a charm for me.
Upvotes: 13