如何从设置屏幕打开位置服务屏幕?

Mon*_*tel 36 objective-c ios location-services

我想以编程方式打开位置服务屏幕以打开服务.

在此输入图像描述

Joe*_*ick 44

位置服务App-Prefs:root=Privacy&path=LOCATION对我有用.当我在设备而不是模拟器上进行测试时.

我不会列出我尝试过的不起作用的东西,这是一个很长的清单.

假定位置服务已禁用或权限被拒绝或未确定的用法示例:

if !CLLocationManager.locationServicesEnabled() {
    if let url = URL(string: "App-Prefs:root=Privacy&path=LOCATION") {
        // If general location settings are disabled then open general location settings
        UIApplication.shared.openURL(url)
    }
} else {
    if let url = URL(string: UIApplicationOpenSettingsURLString) {
        // If general location settings are enabled then open location settings for the app
        UIApplication.shared.openURL(url)
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 由于使用了prefs:root,我的二进制文件被拒绝在应用商店中进行审核 (25认同)
  • 确认Apple拒绝使用`prefs:root`或`App-prefs:root` (18认同)
  • 这可以让苹果拒绝该应用. (7认同)
  • `URL(字符串:"App-prefs:root = LOCATION_SERVICES")`也可以,Swift 4,IOS 11 (4认同)
  • 我的二进制文件被拒绝使用此解决方案。 (2认同)

小智 18

我已经尝试了以上所有答案,它不适用于iOS11 ..它只是打开设置页面而不是应用程序设置..最后这个工作..

UIApplication.shared.open(URL(string:UIApplicationOpenSettingsURLString)!)
Run Code Online (Sandbox Code Playgroud)

Swift 4.2:

UIApplication.shared.open(URL(string:UIApplication.openSettingsURLString)!)
Run Code Online (Sandbox Code Playgroud)

参考:https://developer.apple.com/documentation/uikit/uiapplicationopensettingsurlstring?language = swift

  • 这将在“设置”应用中打开您的应用设置,而不是“位置服务”。 (8认同)
  • 是.避免在您的应用中使用"prefs:root"或"App-Prefs:root",否则App将被拒绝从App Store中删除.只需打开设置页面. (4认同)

Jig*_*iya 11

您可以像使用下面的代码一样直接打开它,

但首先URL Schemes在Info.plist的URL类型中设置如下:

在此输入图像描述

然后在特定事件的下面写一行:

Objective-C中:

[[UIApplication sharedApplication] openURL:
 [NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];
Run Code Online (Sandbox Code Playgroud)

Swift中:

UIApplication.sharedApplication().openURL(NSURL(string: "prefs:root=LOCATION_SERVICES")!)
Run Code Online (Sandbox Code Playgroud)

希望这会帮助你.

  • 截至2018年5月25日,由于使用了prefs:根据指南2.5.1 - 性能 - 软件要求,我们的应用程序被拒绝了 (5认同)
  • 在iOS 10中,我需要使用URL App-Prefs:root = Privacy&path = LOCATION. (4认同)

小智 8

SWIFT 4测试:

避免被拒绝和打开自己的应用程序的位置首选项的唯一方法是:

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

  • 这在 iOS 14 中不适用于调试应用程序,不确定生产情况。只需带您进入“设置”。 (4认同)

Tre*_*v14 7

Swift 4.2

直接进入你的应用程序设置.不要忘记输入您的包标识符 -

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

  • 截至2018年5月25日,由于使用了prefs:根据指南2.5.1 - 性能 - 软件要求,我们的应用程序被拒绝了 (3认同)
  • 更简单: UIApplication.shared.openURL(URL.init(string: UIApplicationOpenSettingsURLString)!) (2认同)
  • @TàTruhoada,如果位置服务被禁用,它是没有用的,您在这里写的是应用程序位置权限,而不是启用/禁用位置服务本身。如果位置服务本身被禁用,您将无法更改应用程序的位置权限 (2认同)

Est*_*cas 5

你想安全吗?使用UIApplicationOpenSettingsURLString,这将打开应用程序设置,没有深层链接

App-prefs正如许多子评论所说,使用您的应用程序将被拒绝。 https://github.com/mauron85/cordova-plugin-background-geolocation/issues/394


Mon*_*tel 3

第1步:点击项目名称>>目标>>信息>>url类型

在此输入图像描述

第2步:

-(IBAction)openSettingViewToEnableLocationService:(id)sender
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];
}
Run Code Online (Sandbox Code Playgroud)

  • Apple 现在禁止使用此 API,您可能不想再使用它,因为它可能会导致应用程序审核被拒绝:/sf/ask/3434176791/ -图形服务器 (5认同)