didUpdateLocations未被调用 [英] didUpdateLocations not being called

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

问题描述

我将对象设置为locationManager的委托,并调用didChangeAuthorizationStatus方法,这样做:

I have my object set as the locationManager's delegate, and the didChangeAuthorizationStatus method is called, which does this:

func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
    if status == CLAuthorizationStatus.AuthorizedWhenInUse {
        self.locationManager.startUpdatingLocation()
    }
}

我也有这种方法,在此之后永远不会被调用:

I also have this method, which never gets called following this:

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
    if locations.count == 0 {
        return
    }

    //Do stuff
}

有任何想法为什么这可能不被称为?我认为被解除分配的对象是一个选项,但是当它达到authorizationStatus方法时它也会被释放。

Any thoughts as to why this might not be being called? I suppose the object being deallocated is an option, but then it'd also be deallocated by the time it hit the authorizationStatus method.

推荐答案

这是一个迟到的答案,但是当我遇到同样的问题时,我偶然发现了这个问题( didChangeAuthorizationStatus 被调用但不是 didUpdateLocations )。当然,这不是代码相关的东西,而是我在没有定位的模拟器中进行测试。因此,从未找到该位置,导致 didUpdateLocations 从未被调用。

This is way late for an answer, but I stumbled across this when I was having the same issue (didChangeAuthorizationStatus was being called but not didUpdateLocations). Well of course it's something not code related, but rather I was testing in the simulator which did not have a location set. Thus the location was never found, resulting in didUpdateLocations never being called.

要修复此问题...模拟器转到调试 - >位置 - > <选择地点>

To fix this... in the simulator go to Debug -> Location-> <choose location>.

编辑还应注意 locationManager:如果未在模拟器中设置位置,则会运行didFailWithError:,如您所料。

EDIT It should also be noted that locationManager:didFailWithError: will run if the location is not set in the simulator, as you'd expect.

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

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