繁体   English   中英

如何在 iOS 11+ 中以编程方式打开设置 > 隐私 > 定位服务?

[英]how to programmatically open Settings > Privacy > Location Services in iOS 11+?

如果 locationServicesEnabled 返回 false,我会提示用户启用他们的位置服务。 以下 URL 适用于 10.0+,将用户重定向到设置应用程序并直接到定位服务屏幕:

URL(字符串:“App-Prefs:root=Privacy&path=LOCATION”)

但是,这在 iOS 11 中不起作用。它会打开“设置”应用程序,但不会深入到定位服务。 有人知道 iOS 11+ 的新 URL 是什么吗?

苹果公司发布了在此链接上明确允许使用的URL列表。 不幸的是,如果您使用其他URL(例如您尝试使用的URL),则会使您的应用程序被App Store拒绝。

简短的答案:您必须遵守App Store的规定,才能做自己想做的事情。

用这个-

UIApplication.shared.open(URL(string:UIApplicationOpenSettingsURLString)!)

使用App-prefs可能会导致拒绝应用程序商店中的应用程序。

或者您也可以尝试以下操作-

if let bundleId = Bundle.main.bundleIdentifier,
let url = URL(string: "\(UIApplication.openSettingsURLString)&path=LOCATION/\(bundleId)") {
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
}

在 iOS 15 中,这对我不起作用,因为它只是打开常规设置页面,但根据shivi_shub回答和他的评论,我尝试了以下操作:

if let bundleId = Bundle.main.bundleIdentifier,
   let url = URL(string: "\(UIApplication.openSettingsURLString)&path=LOCATION_SERVICES/\(bundleId)")
{
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
}

它把我带到了位置设置,至少离我真正想要显示的设置页面更近了几步。

所以我想我们可以这样做:

if let url = URL(string: "\(UIApplication.openSettingsURLString)&path=LOCATION_SERVICES") {
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
}

暂无
暂无

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

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