iOS7核心位置未更新 [英] iOS7 Core Location not updating

查看:114
本文介绍了iOS7核心位置未更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的应用程序示例,用于初始化和更新用户位置。在设备上,它每秒钟成功抛出另一个回调位置,但是在设备上(运行iOS7的iPhone)调用该方法一次,然后神秘地停止.. 。

I have a very simple app example that initialises and updates the users location.. On device it successfully throws another callback location every second or so however on device (iPhone running iOS7) is calls the method once and then mysteriously stops...

//Setup Location Manager in ViewDidLoad
locationManager = [[CLLocationManager alloc] init];
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager setDelegate:self];
[locationManager startUpdatingLocation];

-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
     NSLog(@"location services not turned on");
}

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
     NSLog(@"loactions %@", locations);
}

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

    NSLog(@"new location %f, and old %f", newLocation.coordinate.latitude, newLocation.coordinate.longitude);
}

在iOS6中,这个应用程序完美无缺地更新了设备位置......什么自iOS7以来有变化吗?

In iOS6 this app worked perfectly and continuously updated the devices location... What has changed since iOS7?

推荐答案

这里有几件事情:

1-我没有看到任何属性:pausesLocationUpdatesAutomatically。此属性的默认值为Yes。这意味着根据您的活动类型(参见下面的#2),GPS将暂停更新,这可能是您没有获得更新的原因。该算法是一个只有Apple知道的黑盒子,也许它在iOS6和iOS7之间有所改变。将pausesLocationUpdatesAutomatically设置为NO会影响电池。

1- I don't see anywhere the property: pausesLocationUpdatesAutomatically. The default for this property is Yes. This means that depending on your activityType (see #2) below, the GPS will pause updates and this could be the reason you are not getting updates. The algorithm is a black box that only Apple knows and maybe it somehow changed between iOS6 and iOS7. Setting pausesLocationUpdatesAutomatically to NO can impact the battery.

2-您应根据应用程序设置您的activityType。默认值是CLActivityTypeOther,我不确定它如何影响GPS算法和上面的#1。因此,为了最初测试你的应用程序,我会适当地设置activityType并将pausesLocationUpdatesAutomatically更改为否。在我的测试中,我会得到关于每秒一次的更新(我在一夜之间测试过)。

2- You should set your activityType depending on your application. The default is CLActivityTypeOther which I am not sure how it impact the GPS algorithm and #1 above. So in order to test your app initially, I would set the activityType appropriately and change pausesLocationUpdatesAutomatically to No. In my test, I would get an update about every second consistently (I tested it overnight).

3-位置更新测试需要移动。为了获得更好的结果,我会使用您设置的activityType进行测试。换句话说,如果activityType是CLActivityTypeFitness,我会四处走动来测试它等等。

3- Location updates testing requires movement. In order to get better results, I would use the activityType you set, for testing. In other words, if activityType is CLActivityTypeFitness, I would walk around to test it, etc..

在iOS7中不推荐使用4- locationManager didUpdateToLocation fromLocation。此外,如果实现了locationManager didUpdateLocations,则不会调用前者。所以在上面的例子中,没有调用locationManager didUpdateToLocation fromLocation。

4- locationManager didUpdateToLocation fromLocation is deprecated in iOS7. In addition if locationManager didUpdateLocations is implemented, the former will not be called. So in your case above, locationManager didUpdateToLocation fromLocation is not being called.

5- kCLLocationAccuracyBestForNavigation和kCLLocationAccuracyBest之间没有真正的电池使用差异。在另一方面,kCLLocationAccuracyBestForNavigation使用最高速度GPS和除了与加速度计数据结合它。

5- There is no real battery usage difference between kCLLocationAccuracyBestForNavigation and kCLLocationAccuracyBest. On the other hand, kCLLocationAccuracyBestForNavigation uses top speed GPS and in addition combines it with accelerometer data.

因此,我将与设置activityType,pausesLocationUpdatesAutomatically设置为NO以及改变desiredAccuracy开始kCLLocationAccuracyBestForNavigation。一旦获得持续更新,我就会将pausesLocationUpdatesAutomatically设置为Yes并尝试使用代码来实现相同的应用程序可用性。

So I would start with setting activityType, setting pausesLocationUpdatesAutomatically to NO and changing desiredAccuracy to kCLLocationAccuracyBestForNavigation. Once you are getting continuous updates, then I would set pausesLocationUpdatesAutomatically to Yes and try to work the code to achieve the same app usability.

希望这会有所帮助

这篇关于iOS7核心位置未更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆