gpt4 book ai didi

ios - startMonitoringSignificantLocationChanges() 不能在 xcode 6 Beta2 中使用 swift?

转载 作者:搜寻专家 更新时间:2023-11-01 05:48:14 24 4
gpt4 key购买 nike

我正在尝试对我的位置相关应用程序实现更高效的后台处理,并在这样做的同时学习一些 Swift。

我注意到(困难的方式)我无法在第一个 Beta 中找到工作位置,但切换到 xcode 的 Beta2 解决了这部分问题。

在我的位置处理设置中,我使用这样的代码启动了一个 LocationManager(我希望能够切换到高分辨率,甚至以高模式启动):

locationManager.delegate = self
locationManager.distanceFilter = kCLDistanceFilterNone
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startMonitoringSignificantLocationChanges()

locationManager.startUpdatingLocation();

然后用如下代码处理切换:

if (highResolutionSwitch.on) {
println("Switching to high resolution");
locationManager.stopMonitoringSignificantLocationChanges();
locationManager.startUpdatingLocation();
} else {
println("Switching to low resolution");
locationManager.stopUpdatingLocation();
locationManager.startMonitoringSignificantLocationChanges();
}

当处于“高”模式时,我在我的 didUpdateLocations() 方法中接收到位置,但在“低”模式下从不接收任何内容。是 xcode/swift 环境的 beta 特性还是我遗漏了什么?

最佳答案

发现问题!

问题是对 locationManager.requestWhenInUseAuthorization() 的调用不够。这不会启用重大位置更改。将该行更改为 locationManager.requestAlwaysAuthorization() 至少让模拟器给我一个位置(尽管当我改变位置时没有新位置)。

我将重新部署我的应用程序并查看它是否在 IRL 中运行。

我还需要在模拟器上重新安装该应用程序,以便再次给出“允许”问题。

关于ios - startMonitoringSignificantLocationChanges() 不能在 xcode 6 Beta2 中使用 swift?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24529327/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com