通过提醒等本地通知进行地理定位 [英] Geolocation with local notification like reminder

查看:151
本文介绍了通过提醒等本地通知进行地理定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望实施地理位置通知,例如应用提醒。
这就是我已经做过的事情:

i want implement geolocation notification like the app reminders. this is what i have already done:

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

现在我不知道如何利用这些信息发送本地通知。

Now I have no idea what I have to do to fire local notifications with this information.

推荐答案

我可以告诉你,你的半径可能太小而无法实际触发更新。您将半径设置为1米。这将使位置更新几乎过于精确,无法在测试您传入的坐标上进行注册。

I can tell you that your radius is more than likely too small to actually trigger an update. You have the radius set to 1 meter. That is going to take a location update almost too precise to register on anything other than testing coordinates you pass in.

假设您收到地区事件,我会将您的本地事件 -didEnterRegion -didExitRegion 方法中的通知。您可以像@Missaq一样创建通知。

Assuming you get a region event, I would put your local notification in the -didEnterRegion or -didExitRegion methods. You can create your notification like @Missaq said.

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 。希望这会有所帮助。

Keep in mind that you will not get your notification if your application is active. You will have to be in background mode if you want to see your notification fire. If you application is active, you are expected to present an UIAlertView rather than UILocalNotification. Hope this helps.

这篇关于通过提醒等本地通知进行地理定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆