繁体   English   中英

如何显示启用位置服务弹出窗口

[英]How to show Enable Location Services Popup

如果用户在隐私设置中禁用了位置服务,我该如何显示此弹出窗口。 点击设置按钮打开带有隐私类别的设置,我们不能使用私人 api 来做到这一点,所以我认为这是系统弹出。 但是什么 function 或动作会触发它的出现? 我认为如果位置服务在禁用位置时进行跟踪,系统可能会调用它。 第一

class let openSettingsURLString: String

从此值创建 URL 并将其传递给open(_:options:completionHandler:)方法以启动“设置”应用并显示应用的自定义设置(如果有)。

// Create the URL that deep links to your app's custom settings.
if let url = URL(string: UIApplication.openSettingsURLString) {
    // Ask the system to open that URL.
    await UIApplication.shared.open(url)
}
I guess the second pop up is not the iOS generated but custom one. You can check the location authorization status and then if location is off i.e denied or restricted in this case. So if it's denied or restricted then create a custom alert/action-sheet to show that pop up with title, subtile and button with option asking user to kindly go to setting and make location service on or just dismiss the alert/action sheet if user selects keep negative button i.e location service off button.

 if CLLocationManager.locationServicesEnabled() {
                print("Location service enabled")
                switch CLLocationManager.authorizationStatus() {
                case .notDetermined:
             print("Location service not determined")
                    self.manager.requestWhenInUseAuthorization()
                    self.manager.startUpdatingLocation()
case .restricted, .denied:
                    // Disable location features
                    print("Location service DENIED")l
show that second alert/action sheet here.
case .authorizedWhenInUse, .authorizedAlways:
                    // Enable features that require location services here.
                    print("Full Access")
                    self.manager.startUpdatingLocation()
                @unknown default:
                    print("unknown result")
                }
            } else {
            print("location Services  NOT Enabled")
        }
        }

暂无
暂无

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

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