2013-03-22 114 views
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]]; 
      } 
     } 
    } 

} 
+1

你怎么知道它不工作?你如何测试它?还请注意,重要的位置更改服务不使用所需的准确性属性。当设备连接到不同的蜂窝塔时,您只会获得新的位置。 – rdelmar 2013-03-22 05:09:25

+0

我使用gpx文件在模拟器上测试了它,它在iPhone 6.1上正常工作,但在iPhone 5.1上很差,通过玩弄位置,我可以看到列表已更新,并且我可以在设备处于非活动状态时收到通知,或者终止。但是,当我在实际设备上测试它时,它根本没有工作。我怀疑问题是由于位置更新很大程度上取决于设备上附近的蜂窝塔。 -_- – tom1199 2013-03-22 16:05:51

回答