gpt4 book ai didi

ios - 启用 significantChange 禁用位置

转载 作者:行者123 更新时间:2023-11-28 08:29:34 25 4
gpt4 key购买 nike

我使用 significantChange 监控设备位置,一切正常,每次更改我都会在我的网络服务上更新位置。

如果用户关闭系统位置会怎样? significantChange 是否再调用一次,所以我可以设置该用户已禁用该位置?

最佳答案

在您的 viewDidlaod() 中使用类似这样的东西来检查位置服务的状态。

override func viewDidLoad() {
if CLLocationManager.locationServicesEnabled() {
switch(CLLocationManager.authorizationStatus()) {
case .NotDetermined, .Restricted, .Denied:
print("No access")
case .AuthorizedAlways, .AuthorizedWhenInUse:
print("Access")
}
} else {
print("Last know location: \(location)" // retrieve this from the location you saved it.
// You could also then set some value on your sever to show that it has been turned off.
print("Location services are not enabled")
}
}
}

然后在您的 didUpdateLocations 中保存最后一个位置。

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let location = locations.last // save this in defaults or some way to revive at a later time.
}

关于ios - 启用 significantChange 禁用位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39103056/

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