0

在我的应用程序(部署目标 5.1)中,我使用 CoreLocation 设置提醒功能,它基本上会在设备更新其当前位置时搜索附近的项目(附加位置)。

此功能在现阶段工作不是很稳定,有时无论设备处于活动,挂起和终止状态,它都根本不起作用。我意识到委托方法locationManager:didUpdateToLocation:fromLocation:没有被调用。

有没有人可以为我指出一个方向,让这件事正常工作?

这是我对 CLLocationManager 的设置

sharedLocationManager = [[CLLocationManager alloc]init];
[ESLocationManager defaultManager].delegate = someDelegateClassInstance;
[[ESLocationManager defaultManager] setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
[[ESLocationManager defaultManager] startMonitoringSignificantLocationChanges];

以及委托回调的实现

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

    // If it's a relatively recent event, turn off updates to save power
    NSDate* eventDate = newLocation.timestamp;
    NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
    if (abs(howRecent) < 20.0) {
        // If the event is recent,find nearby items.
        NSLog(@"latitude %+.6f, longitude %+.6f\n",
              newLocation.coordinate.latitude,
              newLocation.coordinate.longitude);

        //reload nearby list
        NSArray *nearbyItems = [self nearbyItemsForLocation:newLocation];
        if (nearbyItems && nearbyItems.count ) {
            UIApplicationState appState = [[UIApplication sharedApplication] applicationState];
            if (appState != UIApplicationStateActive) {
                [[UIApplication sharedApplication] presentLocalNotificationNow:[self localNotificationForItems:nearbyItems]];
            }
        }
    }

}
4

1 回答 1

-1

与此论坛类似的原因与区域监控

https://devforums.apple.com/message/251046#251046

希望这可以帮助

于 2013-06-12T21:29:25.123 回答