gpt4 book ai didi

ios - 如何检查地理定位是否开启?

转载 作者:行者123 更新时间:2023-11-28 13:00:36 25 4
gpt4 key购买 nike

我有一个按钮,它可以获取我的当前位置,但是当我在关闭地理定位的情况下单击它时,应用程序崩溃了。

我想写一个案例,如果用户关闭了他的地理数据,我建议用户通过特殊的警告窗口打开它。

是否有针对此类问题的核心定位方法?

最佳答案

locationManager:didChangeAuthorizationStatus 在 CLLocationManager 初始化后不久被调用。

所以添加这个函数来获取位置状态:

func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
switch status {
case CLAuthorizationStatus.Restricted:
print("Restricted")
case CLAuthorizationStatus.Denied:
print("Denied")
default:
break
}
}

Swift 4 语法:

func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
switch status {
case .restricted:
print("restricted")
case .denied:
print("denied")
case .notDetermined:
print("notDetermined")
case .authorizedAlways:
print("authorizedAlways")
case .authorizedWhenInUse:
print("authorizedWhenInUse")
}
}

Apples reference to CLAuthorizationStatus.

关于ios - 如何检查地理定位是否开启?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33987326/

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