热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

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

I want to open location service screen programmatically to turn on service. enter image description here

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

This screenshot for refrence:

这具有一定的截图:

9 个解决方案

#1


35  

Location services App-Prefs:root=Privacy&path=LOCATION worked for me. When I tested on a device and not a simulator.

Location services App-Prefs:root=Privacy&path= Location为我工作。当我在一个设备而不是模拟器上测试的时候。

I won't list the things I tried that did not work, it's a long list.

我不会列出我尝试过的那些没用的东西,这是一个很长的列表。

Usage example that assumes either location services are disabled or permission is denied or not determined:

假定任何位置服务被禁用或被拒绝或未确定的使用示例:

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)
    }
}

#2


11  

You can open it directly like using below code,

你可以直接用下面的代码打开它,

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

但是首先在Info中设置URL模式。plist的URL类型:

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.

希望这对你有帮助。

#3


4  

First:

第一:

Add URL

添加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

#4


4  

Swift 3

斯威夫特3

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

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

if let url = URL(string: "App-Prefs:root=Privacy&path=LOCATION/your.bundle.identifier") {
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
}

#5


3  

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

步骤1:点击项目名称>>目标>> info >> url类型

enter image description here

Step 2:

步骤2:

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

#6


1  

After adding prefs as a url type, use the following code to go directly to the location settings of an application.

在将prefs作为url类型添加之后,使用以下代码直接进入应用程序的位置设置。

if let url = URL(string: "App-prefs:root=LOCATION_SERVICES") {
     UIApplication.shared.open(url, options: [:], completionHandler: nil)
}

#7


1  

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)
}

#8


1  

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)!)

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

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

#9


0  

Updated code for Xcode 9.3, swift 4

更新代码为Xcode 9.3, swift 4

    let settingsUrl = URL(string: UIApplicationOpenSettingsURLString)
    if UIApplication.shared.canOpenURL(settingsUrl!)  {
        if #available(iOS 10.0, *) {
            UIApplication.shared.open(settingsUrl!, completionHandler: { (success) in
            })
        }
        else  {
            let url = URL(string : "prefs:root=")
            if UIApplication.shared.canOpenURL(url!) {
                UIApplication.shared.openURL(url!)
            }
        }
    }

推荐阅读
author-avatar
汪pallotta
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有