简体   繁体   English

从隐私->定位服务->在iPhone中关闭位置

[英]location disabled from Privacy->Location Services -> off in iPhone

How to add custom message if location disabled from Privacy->Location Services -> off.如果从隐私-> 定位服务-> 关闭位置禁用,如何添加自定义消息。 I am using iPhone11 and getting apple issues as to add description about application if disabled also.我正在使用 iPhone11 并遇到苹果问题,如果也被禁用,则添加有关应用程序的描述。 Please suggest.请建议。

You can do something like this in your locationManager class.你可以在你的 locationManager 类中做这样的事情。

func checkLocationServices() {
    if CLLocationManager.locationServicesEnabled() {
        setupLocationManager()
        checkLocationAuthorization()
    } else {
        // Show alert letting the user know they have to turn this on.
         self.delegate?.showLocationServiceDialog(status: 2)
    }
}

func checkLocationAuthorization() {
    switch CLLocationManager.authorizationStatus() {
    case .authorizedWhenInUse:
        locationManager?.startUpdatingLocation()
        break
    case .denied:
        //I'm sorry - I can't show location. User has not authorized it
        self.delegate?.showLocationPermissionDialog(status: 0)
        break
    case .notDetermined:
        locationManager!.requestAlwaysAuthorization()
    case .restricted:
        // Access to Location Services is Restricted", message: "Parental Controls or a system administrator may be limiting your access to location services. Ask them to.
        self.delegate?.showLocationPermissionDialog(status: 1)
        break
    case .authorizedAlways:
        locationManager?.startUpdatingLocation()
        break
    @unknown default:
        print("Unknown permission status")
    }
}

In function checkLocationServices() you can show alert to the user if CLLocationManager.locationServicesEnabled() returns false.在函数 checkLocationServices() 中,如果 CLLocationManager.locationServicesEnabled() 返回 false,您可以向用户显示警报。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM