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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37654132/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:16:04  来源:igfitidea点击:

How to open Location services screen from setting screen?

iosobjective-clocation-services

提问by Monika Patel

I want to open location service screen programmatically to turn on service.

我想以编程方式打开定位服务屏幕以打开服务。

enter image description here

在此处输入图片说明

采纳答案by Monika Patel

Step 1: Click on project name >> target>> info >> url Types

第一步:点击项目名称>>目标>>信息>>网址类型

enter image description here

在此处输入图片说明

Step 2:

第2步:

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

回答by Vijay Karthik

I have tried all the above answers,it's not working on iOS11..it just opens settings page and not the app settings .. Finally this works..

我已经尝试了上述所有答案,它在 iOS11 上不起作用..它只是打开设置页面而不是应用程序设置..最后这有效..

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

Swift 4.2:

斯威夫特 4.2:

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

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

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

回答by 3vangelos

SWIFT 4 tested:

SWIFT 4 测试:

Only way to avoid getting rejected and open Location Preferences of own app is:

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

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

回答by Jigar Tarsariya

You can open it directly like using below code,

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

But first set URL Schemesin Info.plist's URL Type Like:

但首先URL Schemes在 Info.plist 的 URL Type Like 中设置:

enter image description here

在此处输入图片说明

Then write below line at specific event:

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

In Objective - C:

目标-C 中

[[UIApplication sharedApplication] openURL:
 [NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];

In Swift:

斯威夫特

UIApplication.sharedApplication().openURL(NSURL(string: "prefs:root=LOCATION_SERVICES")!)

Hope this will help you.

希望这会帮助你。

回答by Trev14

Swift 4.2

斯威夫特 4.2

Go straight to YOUR app's settings like this. Don't forget to put in your bundle identifier -

像这样直接进入您的应用程序设置。不要忘记输入您的包标识符 -

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

回答by Ronak Chaniyara

First:

第一的:

Add URL

添加网址

Go to Project settings --> Info --> URL Types --> Add New URL Schemes

转到项目设置 --> 信息 --> URL 类型 --> 添加新的 URL 方案

See image below:

见下图:

Second:

第二:

Use below code to open Location settings:

使用以下代码打开位置设置:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];

referred from: https://stackoverflow.com/a/35987082/5575752

引用自:https: //stackoverflow.com/a/35987082/5575752

回答by Estev?o Lucas

Do you want to be safe? use UIApplicationOpenSettingsURLString, which will open the app settings, without deep-link.

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

Using App-prefsyour app will be rejected, as many sub comments said. https://github.com/mauron85/cordova-plugin-background-geolocation/issues/394

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

回答by Nicolas Madrid

If you set locationManager.startUpdatingLocation() and you have disabled on your iphone, it automatically show you an alertView with the option to open and activated location.

如果您设置了 locationManager.startUpdatingLocation() 并且您在 iPhone 上禁用了它,它会自动向您显示一个带有打开和激活位置选项的 alertView。

回答by Shakeel Ahmed

Swift 5+
Easy Way Direct Your said application page will open

Swift 5+
Easy Way Direct 您所说的应用程序页面将打开

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

回答by Mateusz Grzegorzek

Actually there's much simpler solution to that. It'll show your app settings with loction services/camera access, etc.:

实际上有更简单的解决方案。它会显示您的应用设置以及位置服务/相机访问等:

func showUserSettings() {
    guard let urlGeneral = URL(string: UIApplicationOpenSettingsURLString) else {
        return
    }
    UIApplication.shared.open(urlGeneral)
}