具有本地通知(如提醒)的地理位置

发布于 2024-12-29 22:37:20 字数 951 浏览 1 评论 0原文

我想像应用程序提醒一样实现地理位置通知。 这是我已经完成的:

在应用程序委托中:

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

现在我不知道我必须做什么才能触发本地包含此信息的通知。

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

in App delegate:

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
{

}

And this one in the view controller witch starts monitoring:

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

余生共白头 2025-01-05 22:37:20

我可以告诉你,你的半径很可能太小而无法实际触发更新。您将半径设置为 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。希望这有帮助。

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.

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

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.

墨落成白 2025-01-05 22:37:20

尝试使用

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

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

委托方法。

Try to use the

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

and

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

delegate methods.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文