具有本地通知(如提醒)的地理位置
我想像应用程序提醒一样实现地理位置通知。 这是我已经完成的:
在应用程序委托中:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可以告诉你,你的半径很可能太小而无法实际触发更新。您将半径设置为 1 米。这将需要位置更新几乎太精确,无法在您传入的测试坐标之外的任何内容上注册。
假设您收到区域事件,我会将您的本地通知放入
-didEnterRegion
或-didExitRegion
方法。您可以像@Missaq 所说的那样创建通知。请记住,如果您的申请处于活动状态,您将不会收到通知。如果您想看到通知触发,您必须处于后台模式。如果您的应用程序处于活动状态,则您应该显示
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.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 thanUILocalNotification
. Hope this helps.尝试使用
和
委托方法。
Try to use the
and
delegate methods.