CLLocationManager不能一直工作(iOS 8,Xcode 6) [英] CLLocationManager not working all the time (iOS 8, Xcode 6)

查看:71
本文介绍了CLLocationManager不能一直工作(iOS 8,Xcode 6)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上一半的委托方法

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations;

根本没有被调用。但另一半时间它完美运作!我发现它通常发生在我关闭并退出它之后第一次启动Xcode时,但之后在那之后或者几次运行之后它似乎工作正常。我不是100%确定它是否只是一个Xcode问题或者什么,我很快就会获得开发人员的许可证,所以我会看看它是否能在实际设备上正常工作。

is not called at all. But the other half of the time it works perfectly! I've found that it usually happens when I first start up Xcode after closing and quitting it, but then after that or a couple runs after that it seems to work fine. I'm not 100% sure if it's just an Xcode problem or what, I'll be getting a developer's license soon so I'll see if it will work fine on an actual device.

从viewDidAppear开始(在viewDidLoad中尝试也没有区别),我运行一个方法来初始化我的locationManager东西:

Starting from the viewDidAppear (tried in viewDidLoad also, made no difference), I run a method to init my locationManager stuff:

locationManager = [[CLLocationManager alloc]init];

[locationManager setDelegate:self];
locationManager.distanceFilter = 20.0f;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.pausesLocationUpdatesAutomatically = NO;

if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)])
    [locationManager requestAlwaysAuthorization];

[locationManager startUpdatingLocation];

有时这种方法有效,有时则不然。我甚至做了一个计时器,每隔一秒钟就重新运行一次,但这不起作用。

Sometimes this works, sometimes it doesn't. I even made a timer to re-run this every so-and-so seconds, and this doesn't work.

还有什么我应该做的吗?这个问题有什么答案吗?

Is there something else I should do? Is there any answer to this problem?

谢谢。

推荐答案

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations;  

仅当新位置可用时才会调用此委托方法。有时gps不会获得卫星信号,因此无法获得位置。因此在这些情况下,上述方法不会被触发。由于您在模拟器中进行测试,因此您应该更改或设置位置。我认为它可以在实际设备上正常工作。

This delegate method is invoked only if new locations are available. Sometimes gps will not get satellite signal hence locations cannot be obtained. So in these situations the above mentioned method will not get triggered. Since you are testing in simulator,you should change or set the location. I think it will work fine on an actual device.

这篇关于CLLocationManager不能一直工作(iOS 8,Xcode 6)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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