地理位置和当地通知一样提醒

我想实施地理位置通知,如应用程序提醒。 这是我已经做了:

在App委托中:

self.locationManager = [[[CLLocationManager alloc] init] autorelease]; /* don't leak memeory! */ [self.locationManager setDelegate:self]; [self.locationManager setDesiredAccuracy:kCLLocationAccuracyBest]; -(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region { } -(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region { } -(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { } 

而这个在视图控制器中的女巫开始监视:

 CLLocationCoordinate2D location2D = mapView.region.center; CLRegion *regionForMonitoring = [[CLRegion alloc] initCircularRegionWithCenter:location2D radius:1 identifier:@"RegionIdentifier"]; [[Utils getLocationManager] startMonitoringForRegion:regionForMonitoring]; 

现在我不知道要用这些信息来触发本地通知。

我可以告诉你,你的半径很可能太小而不能实际触发更新。 你的半径设置为1米。 这就要求位置更新几乎精确到除了通过testing坐标之外的任何其他地方。

假设你得到一个区域事件,我会把你的本地通知放在-didEnterRegion-didExitRegion方法中。 你可以像@Missaq所说的那样创build你的通知。

 UILocalNotification *notification = [[UILocalNotification alloc] init]; notification.fireDate = [NSDate date]; NSTimeZone* timezone = [NSTimeZone defaultTimeZone]; notification.timeZone = timezone; notification.alertBody = @"Notification message"; notification.alertAction = @"Show"; notification.soundName = UILocalNotificationDefaultSoundName; [[UIApplication sharedApplication] scheduleLocalNotification:notification]; [notification release]; // release if not using ARC 

请记住,如果您的应用程序处于活动状态,则不会收到通知。 如果你想看到你的通知消息,你将不得不处于后台模式。 如果您的应用程序处于活动状态,则需要提供UIAlertView而不是UILocalNotification 。 希望这可以帮助。

尝试使用

 - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region; 

 - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region; 

委托方法。

Interesting Posts