热门标签 | 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!)
            }
        }
    }

推荐阅读
  • Python正则表达式学习记录及常用方法
    本文记录了学习Python正则表达式的过程,介绍了re模块的常用方法re.search,并解释了rawstring的作用。正则表达式是一种方便检查字符串匹配模式的工具,通过本文的学习可以掌握Python中使用正则表达式的基本方法。 ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • 向QTextEdit拖放文件的方法及实现步骤
    本文介绍了在使用QTextEdit时如何实现拖放文件的功能,包括相关的方法和实现步骤。通过重写dragEnterEvent和dropEvent函数,并结合QMimeData和QUrl等类,可以轻松实现向QTextEdit拖放文件的功能。详细的代码实现和说明可以参考本文提供的示例代码。 ... [详细]
  • IhaveconfiguredanactionforaremotenotificationwhenitarrivestomyiOsapp.Iwanttwodiff ... [详细]
  • 开发笔记:加密&json&StringIO模块&BytesIO模块
    篇首语:本文由编程笔记#小编为大家整理,主要介绍了加密&json&StringIO模块&BytesIO模块相关的知识,希望对你有一定的参考价值。一、加密加密 ... [详细]
  • CSS3选择器的使用方法详解,提高Web开发效率和精准度
    本文详细介绍了CSS3新增的选择器方法,包括属性选择器的使用。通过CSS3选择器,可以提高Web开发的效率和精准度,使得查找元素更加方便和快捷。同时,本文还对属性选择器的各种用法进行了详细解释,并给出了相应的代码示例。通过学习本文,读者可以更好地掌握CSS3选择器的使用方法,提升自己的Web开发能力。 ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 本文讨论了使用差分约束系统求解House Man跳跃问题的思路与方法。给定一组不同高度,要求从最低点跳跃到最高点,每次跳跃的距离不超过D,并且不能改变给定的顺序。通过建立差分约束系统,将问题转化为图的建立和查询距离的问题。文章详细介绍了建立约束条件的方法,并使用SPFA算法判环并输出结果。同时还讨论了建边方向和跳跃顺序的关系。 ... [详细]
  • Android Studio Bumblebee | 2021.1.1(大黄蜂版本使用介绍)
    本文介绍了Android Studio Bumblebee | 2021.1.1(大黄蜂版本)的使用方法和相关知识,包括Gradle的介绍、设备管理器的配置、无线调试、新版本问题等内容。同时还提供了更新版本的下载地址和启动页面截图。 ... [详细]
  • CF:3D City Model(小思维)问题解析和代码实现
    本文通过解析CF:3D City Model问题,介绍了问题的背景和要求,并给出了相应的代码实现。该问题涉及到在一个矩形的网格上建造城市的情景,每个网格单元可以作为建筑的基础,建筑由多个立方体叠加而成。文章详细讲解了问题的解决思路,并给出了相应的代码实现供读者参考。 ... [详细]
  • iOS逆向工程(三):利用Cycript调试App
    利用Cycript调试App一、Cycript是什么?Cycript是一种脚本语言,是Ob ... [详细]
  • IvebeentryingforadayortwototryandgetashadowtodrawinsidethetextofanNSTextField ... [详细]
  • Iamtryingtomakeaclassthatwillreadatextfileofnamesintoanarray,thenreturnthatarra ... [详细]
  • 本文讨论了在Windows 8上安装gvim中插件时出现的错误加载问题。作者将EasyMotion插件放在了正确的位置,但加载时却出现了错误。作者提供了下载链接和之前放置插件的位置,并列出了出现的错误信息。 ... [详细]
  • JavaSE笔试题-接口、抽象类、多态等问题解答
    本文解答了JavaSE笔试题中关于接口、抽象类、多态等问题。包括Math类的取整数方法、接口是否可继承、抽象类是否可实现接口、抽象类是否可继承具体类、抽象类中是否可以有静态main方法等问题。同时介绍了面向对象的特征,以及Java中实现多态的机制。 ... [详细]
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社区 版权所有