1

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

在应用委托

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]; 

现在我没有了解我必须做些什么才能用此信息激发本地通知。

回答

5

我可以告诉你,你的半径很可能太小而不能实际触发更新。你的半径设置为1米。这是要采取一个位置更新几乎是太精确到比测试以外的任何坐标注册你通过。

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

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。希望这可以帮助。

+0

是的,这是... 1米是问题!谢谢!! – Missaq 2012-01-30 16:43:02

+0

太棒了!乐意效劳。感谢你的接纳。 – 2012-01-30 16:45:49

+0

我在挖这个话题。通过这种方法,只有在你的应用程序唤醒时才触发methode'didEnterRegion'。即使您的应用程序未启动,是否可以进行地理定位通知? – 2012-09-28 10:10:15

2

尝试使用

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

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

委托方法。

+0

我在这个方法中要做什么? – Missaq 2012-01-30 12:56:13

+0

好 - 创建本地通知? – 2012-01-30 13:21:34

+0

像这样:' - (void)locationManager:(CLLocationManager *)manager didEnterRegion :(CLRegion *)region { UILocalNotification * notif = [[UILocalNotification alloc] init]; notif.fireDate = [NSDate date]; NSTimeZone * tz = [NSTimeZone defaultTimeZone]; notif.timeZone = tz; notif.alertBody = @“Did enter Region”; notif.alertAction = @“Show”; notif.soundName = UILocalNotificationDefaultSoundName; [[UIApplication sharedApplication] scheduleLocalNotification:notif]; }' – Missaq 2012-01-30 13:37:29