我在 AppDelegate 文件中使用 Swift 在我的应用程序中添加了 CLLocationManager。
在 Appdelegate.swift 文件中,
import CoreLocation
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {
var locationManager: CLLocationManager!
在 didbecomeActive 方法中:
func applicationDidBecomeActive(application: UIApplication) {
if((locationManager) != nil)
{
locationManager.stopMonitoringSignificantLocationChanges()
locationManager.delegate = nil
locationManager = nil
}
locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.activityType = CLActivityType.OtherNavigation
locationManager.requestAlwaysAuthorization()
locationManager.startMonitoringSignificantLocationChanges()
}
如果我使用startUpdatingLocation
, didUpdateLocations
方法被调用,但不是为了startMonitoringSignificantLocationChanges
.
为什么没有被要求startMonitoringSignificantLocationChanges
。
我正在ios模拟器中测试这个。我不知道如何检查设备。
它正在工作,但是很难触发重大的位置变化 - 它通常发生在设备改变手机信号塔时 - 我认为模拟器不可能做到这一点。
您可能必须骑自行车/汽车并行驶至少几公里。
不过,您可以使用一个技巧,它将触发显着的位置变化:
以几秒的间隔反复打开和关闭 iPhone 中的飞行模式,它应该会欺骗设备,使其认为它更改了手机信号塔并触发显着的位置变化。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)