【问题标题】:Local notification based on geo location基于地理位置的本地通知
【发布时间】:2014-04-29 13:39:56
【问题描述】:

我的项目包含一个 mapView,其中的对象作为引脚放置在不同的位置。

当用户进入其中一个引脚的区域时,我希望触发本地通知,告诉用户他在该特定对象附近。我已经查看了文档,但似乎无法解决。

如果你想看看,我已经发布了我的代码here。

【问题讨论】:

    标签: ios geolocation notifications mkmapview local


    【解决方案1】:

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

    【讨论】:

    • 我已经这样做了,但是没有调用 didEnterRegion。我究竟做错了什么?在这里查看我的代码pastebin.com/uNA4fwWY
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-11
    • 2016-12-29
    • 1970-01-01
    • 1970-01-01
    • 2012-04-19
    • 1970-01-01
    相关资源
    最近更新 更多