UILocalNotification scheduled in the background does not fire

I have an application that runs in the background using location services (through significant location updates). Whenever a significant place is updated, it is called - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations, and then I call [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:...to start the background job. Then I try to run a local notification:

UILocalNotification *notif = [[UILocalNotification alloc] init];
[notif setAlertAction:@"Test"];
[[UIApplication sharedApplication] presentLocalNotificationNow:notif];

However, the notification is not provided to the user. Local notifications can not be sent from the background? Any help is appreciated.

Thanks,

+4
source share
1 answer

You need a fire date:

UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = text;
notification.fireDate = [[NSDate alloc] initWithTimeIntervalSinceNow:0];
notification.timeZone = [NSTimeZone defaultTimeZone];
notification.repeatInterval = 0;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
+1

All Articles