【问题标题】:startMonitoringSignificantLocationChanges() not working with swift in xcode 6 Beta2?startMonitoringSignificantLocationChanges() 在 xcode 6 Beta2 中不能与 swift 一起使用?
【发布时间】:2014-07-02 10:55:23
【问题描述】:

我正在尝试对我的位置相关应用程序实现更有效的后台处理,并在此过程中学习一些 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-environment 的 beta 特性还是我遗漏了什么?

【问题讨论】:

  • 你是在模拟器还是真机上测试?
  • 我正在测试两者。它现在可以工作了(我自己的回应)

标签: ios xcode swift location-services


【解决方案1】:

发现问题!

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

我将重新部署我的应用,看看它是否适用于 IRL。

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

【讨论】:

  • 我早上喝咖啡之前是不是太早了,还是你的答案中的旧电话和新电话相同?
  • @Matt 你是 100% 正确的,我会把它改成函数 requestAlwaysAuthorization()
猜你喜欢
  • 2016-03-10
  • 1970-01-01
  • 2016-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-11
  • 2023-03-25
相关资源
最近更新 更多