簡體   English   中英

從隱私->定位服務->在iPhone中關閉位置

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

如果從隱私-> 定位服務-> 關閉位置禁用,如何添加自定義消息。 我正在使用 iPhone11 並遇到蘋果問題,如果也被禁用,則添加有關應用程序的描述。 請建議。

你可以在你的 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,您可以向用戶顯示警報。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM