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]];
}
}
}
}
你怎麼知道它不工作?你如何測試它?還請注意,重要的位置更改服務不使用所需的準確性屬性。當設備連接到不同的蜂窩塔時,您只會獲得新的位置。 – rdelmar 2013-03-22 05:09:25
我使用gpx文件在模擬器上測試了它,它在iPhone 6.1上正常工作,但在iPhone 5.1上很差,通過玩弄位置,我可以看到列表已更新,並且我可以在設備處於非活動狀態時收到通知,或者終止。但是,當我在實際設備上測試它時,它根本沒有工作。我懷疑問題是由於位置更新很大程度上取決於設備上附近的蜂窩塔。 -_- – tom1199 2013-03-22 16:05:51