I am trying to get a local notification to fire any time I turn on my phone and I am inside a specific region. This works as expected but each time I turn my device on I get a new notification. If I just leave the existing notification it can get pushed down to the bottom of the notification list. If I cancel the existing notification and create a new one I get a weird animation. Is there a way to either:
- Update an existing UILocalNotification that has already been delivered to push it to the top.
- Somehow get notified when the lock screen goes away and cancel the notification then?
Here is my existing code:
- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region {
if ([region isKindOfClass:[CLBeaconRegion class]]) {
CLBeaconRegion *beaconRegion = (CLBeaconRegion*)region;
UILocalNotification *existingNotification = self.beaconNotification;
switch (state) {
case CLRegionStateInside:
self.beaconNotification = [[UILocalNotification alloc] init];
self.beaconNotification.alertBody = @"You're inside the region";
[[UIApplication sharedApplication] presentLocalNotificationNow:self.beaconNotification];
if (existingNotification) {
[[UIApplication sharedApplication] cancelLocalNotification:existingNotification];
}
break;
case CLRegionStateOutside:
self.beaconNotification = [[UILocalNotification alloc] init];
self.beaconNotification.alertBody = @"You're outside the region";
[[UIApplication sharedApplication] cancelAllLocalNotifications];
break;
default:
break;
}
}
}