一段时间后未调用CLLocationManager didUpdateToLocation [英] CLLocationManager didUpdateToLocation not being called after some time

查看:54
本文介绍了一段时间后未调用CLLocationManager didUpdateToLocation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随着时间的推移,我试图记录用户的位置。如果用户在移动中工作正常,则可以可靠地调用委托方法didUpdateToLocation。但是,如果用户静止不动且应用在后台运行,则一段时间后将不再调用委托方法。要重新启动它,需要将该应用购买到前台。一旦激活,则再次可靠地调用委托方法。

I am trying to record a users location over time. If the user is on the move it works fine and the delegate method didUpdateToLocation is invoked reliably.However if the user is stationary and the app is running in the background then after some time, the delegate method is no longer invoked. To restart it, the app needs to be bought into the foreground. Once it is active the delegate method is invoked reliably again.

我最初认为这可能是由于CLLocationManager对象是在ViewController中声明的事实,所以我将其更改为在AppDelegate中声明的,但事实并非如此要么帮助。

I initially thought that this could be due to the fact that the CLLocationManager object was declared within a ViewController, so I changed it to be declared within the AppDelegate but that did not help either.

我也尝试过distanceFilter属性无济于事。我目前正在View控制器中使用以下代码对其进行设置。请注意,对象本身是在AppDelegate对象中声明和初始化的。

I have also experimented with the distanceFilter property to no avail. I am currently setting it up using the following code from within a View controller. Note that the object itself is declared and initialized in the AppDelegate object.

 app.locationManager.delegate = self;
    app.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    app.locationManager.distanceFilter = kCLDistanceFilterNone;
    [app.locationManager startUpdatingLocation];

还有其他人遇到此问题吗?任何指针将不胜感激。我已经为此苦苦挣扎了几天。

Has anyone else run into this issue? Any pointers would be appreciated. I have been struggling with this for a few days now.

推荐答案

iOS 6引入了CLLocationManager属性 pausesLocationUpdatesAutomatically。设置CLLocationManager时,需要将其设置为NO,如下所述: http://www.stackoverflow.com/ a / 12781634/700769

iOS 6 introduces the CLLocationManager property pausesLocationUpdatesAutomatically. It needs to be set to NO when you set up your CLLocationManager, as described here: http://www.stackoverflow.com/a/12781634/700769

这篇关于一段时间后未调用CLLocationManager didUpdateToLocation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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