0

如果从“隐私”->“位置服务”->“关闭”禁用位置,如何添加自定义消息。我正在使用 iPhone11 并遇到苹果问题,以便在禁用时添加有关应用程序的描述。请建议。

4

1 回答 1

1

你可以在你的 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")
    }
}

在函数 checkLocationServices() 中,如果 CLLocationManager.locationServicesEnabled() 返回 false,您可以向用户显示警报。

于 2020-02-06T09:40:39.437 回答