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

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

问题描述

我有一个非常简单的应用程序示例,用于初始化和更新用户位置..

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- 您应该根据您的应用程序设置您的活动类型.默认值为 CLActivityTypeOther,我不确定它如何影响 GPS 算法和上面的 #1.因此,为了最初测试您的应用,我会适当地设置 activityType 并将 pausesLocationUpdatesAutomatically 更改为 No.在我的测试中,我会持续获得大约每秒的更新(我在一夜之间对其进行了测试).

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 是 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..

4- locationManager didUpdateToLocation fromLocation 在 iOS7 中已弃用.另外如果 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天全站免登陆