Regional Local Notification

Im currently working with "Regions" Sample code: https://developer.apple.com/library/ios/#samplecode/Regions/Introduction/Intro.h tml # // apple_ref / doc / uid / DTS40010726-Intro- DontLinkElementID_2

I would like to take one more step and generate or ignite when the user leaves the region (maybe for both entering and exiting, I do not mind, which is easier for the initial implementation).

I looked at a link to the CLLocation class, location programming guide, local and push notification programming guide. And he suffers from information overload.

Many thanks:)

EDIT: I think I might come up with an idea that solves the problem: in the RegionsViewController implementation file there is the following:

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region { NSString *event = [NSString stringWithFormat:@"didExitRegion %@ at %@", region.identifier, [NSDate date]]; [self updateWithEvent:event]; } 

Since I want to implement local notification when the user leaves the specified border of the area, I entered this:

 - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region { NSString *event = [NSString stringWithFormat:@"didExitRegion %@ at %@", region.identifier, [NSDate date]]; [self updateWithEvent:event]; //implement local notification: UIApplication *app = [UIApplication sharedApplication]; UILocalNotification *notification = [[UILocalNotification alloc] init]; [[UIApplication sharedApplication] cancelAllLocalNotifications]; if (notification == nil) return; notification.alertBody = [NSString stringWithFormat:@"Did You Lock Your House?"]; notification.alertAction = @"Lock House"; notification.soundName = UILocalNotificationDefaultSoundName; notification.applicationIconBadgeNumber = 1; [app presentLocalNotificationNow:notification]; [notification release]; } 

Can someone advise me if this is correct or any recommendations? (apologies for poor formatting)

+6
source share
1 answer

you're right, there is no better way than starting a local notification from locationManager: didExitRegion: Moreover, it will work even if your application is running in the background or closed.

+1
source

Source: https://habr.com/ru/post/912495/


All Articles