【发布时间】:2014-04-29 13:39:56
【问题描述】:
我的项目包含一个 mapView,其中的对象作为引脚放置在不同的位置。
当用户进入其中一个引脚的区域时,我希望触发本地通知,告诉用户他在该特定对象附近。我已经查看了文档,但似乎无法解决。
如果你想看看,我已经发布了我的代码here。
【问题讨论】:
标签: ios geolocation notifications mkmapview local
我的项目包含一个 mapView,其中的对象作为引脚放置在不同的位置。
当用户进入其中一个引脚的区域时,我希望触发本地通知,告诉用户他在该特定对象附近。我已经查看了文档,但似乎无法解决。
如果你想看看,我已经发布了我的代码here。
【问题讨论】:
标签: ios geolocation notifications mkmapview local
MKMapView 擅长显示用户的位置,但您需要使用 CoreLocation 来确定用户是否进入特定区域。特别是,您需要查看CLLocationManager 类的-startMonitoringForRegion: 方法。您应该从CLLocationManagerDelegate 实现-locationManager:didEnterRegion: 委托方法并从那里触发您的本地通知。
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
// Create a region centered around a map pin
// You'll need to do this for every pin region you wish to monitor
CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter:pinCenter
radius:regionRadius
identifier:yourRegionIdentifier];
[self.locationManager startMonitoringForRegion:region];
.
.
.
- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = @"You entered a region";
notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}
【讨论】: