10
votes

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.

2

2 Answers

13
votes

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.

4
votes

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.