简体   繁体   English

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

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

If locationServicesEnabled return false, I'm prompting the user to enable their Location Services.如果 locationServicesEnabled 返回 false,我会提示用户启用他们的位置服务。 The following URL works for 10.0+, redirecting the user to the Settings app and directly to the Location Services screen:以下 URL 适用于 10.0+,将用户重定向到设置应用程序并直接到定位服务屏幕:

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

However this doesn't work in iOS 11. It opens the Settings app, but doesn't drill down to the Location Services.但是,这在 iOS 11 中不起作用。它会打开“设置”应用程序,但不会深入到定位服务。 Anyone knows what's the new URL for iOS 11+?有人知道 iOS 11+ 的新 URL 是什么吗?

Apple published a list of URLs which they explicitly allow at this link . 苹果公司发布了在此链接上明确允许使用的URL列表。 Unfortunately if you use other URLs (such as the one you are trying to use) this can get your app rejected from the App Store. 不幸的是,如果您使用其他URL(例如您尝试使用的URL),则会使您的应用程序被App Store拒绝。

Short answer: You cannot do what you are trying to do without breaking the App Store rules. 简短的答案:您必须遵守App Store的规定,才能做自己想做的事情。

Use this- 用这个-

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

Using App-prefs may lead to the rejection of the app on app store. 使用App-prefs可能会导致拒绝应用程序商店中的应用程序。

Or you can try this also- 或者您也可以尝试以下操作-

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

In iOS 15 this wasn't working for me, as it was just opening the general settings page, but based on shivi_shub answer and his comment I tried the following:在 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)
}

And it brought me to the location settings, which at least is a couple steps closer to the settings page I really want to show.它把我带到了位置设置,至少离我真正想要显示的设置页面更近了几步。

So I guess we could just do:所以我想我们可以这样做:

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.

相关问题 如何从iOS 11 beta版的iOS应用程序中打开位置服务? - How to open Location Services from iOS application for iOS 11 beta? 以编程方式更改iOS上的隐私设置 - Programmatically changing privacy settings on iOS 即使存在密钥,IOS 11+位置服务授权也会失败 - IOS 11+ Location Services Authorization fails even though keys exist 打开位置设置在iOS 11中不起作用 - Open location settings not working in iOS 11 可以通过编程方式重置位置和隐私设置吗? - Can the Location and Privacy settings be reset programmatically? 如何在iOS中以编程方式打开设置 - How to open settings programmatically in ios iOS设置(隐私 - >位置服务 - >选择我的应用 - >更改允许访问)崩溃 - iOS settings (Privacy -> Location services -> select my app -> change allow access) crashed 如何直接为ios11打开位置隐私设置页面?由于以下代码不起作用,因此仅打开设置屏幕 - How to open Location Privacy Setting Page directly for ios11 ?As below code is not working , it opens setting screen only iOS CoreLocation:如果通过设备设置禁用了位置服务,如何以编程方式处理 - iOS CoreLocation: How to handle programmatically if location services are disabled from device settings 我的应用程序未显示在位置服务下(设置->隐私) - My application is not showing under location services (Settings->Privacy)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM