Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 532
Henry Brown Avatar asked Aug 28 '15 12:08

Henry Brown


People also ask

Do local notifications work when app is closed?

The local notification should occur at the schedule time even if the app is closed.

Can you send local notifications while app is in background?

Notifications could be created at any moment (on Foreground, Background or even when the application is terminated/killed).

What is local notification in Android?

Local notifications are scheduled by an app and delivered on the same device. They are suited for apps with time-based behaviors, such as calendar events. When you run your app on a device with Android OS 8.0 or above, Kony uses default channels that are mentioned in the localnotificationconfig.

What is local push notification?

A Push Notification is sent from a server and it requires internet on your device to receive it.


2 Answers

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.

like image 139
Johannes Avatar answered Oct 13 '22 13:10

Johannes


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.

like image 39
picciano Avatar answered Oct 13 '22 13:10

picciano