Henry Brown
Henry Brown

Reputation: 2237

Sending local notifications after the app has been terminated

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

Answers (2)

picciano
picciano

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

Johannes
Johannes

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

Related Questions