简体   繁体   English

打开位置设置在iOS 11中不起作用

[英]Open location settings not working in iOS 11

I'm using this code to redirect to iOS settings for the location: 我正在使用以下代码将位置重定向到iOS设置:

NSURL *url = [NSURL URLWithString:@"App-Prefs:root=LOCATION_SERVICES"];

if ([[UIApplication sharedApplication] canOpenURL:url]) {
    [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
}

But it is just redirecting to settings and not in location or bluetooth settings. 但这只是重定向到设置,而不是在位置或蓝牙设置中。 Does anybody know if is any way to redirect to iOS location settings? 有人知道是否有任何方法可以重定向到iOS位置设置吗?

Thank you 谢谢

Declare url as: url声明为:

NSURL *url = [NSURL URLWithString:@"App-Prefs:root=LOCATION_SERVICES"];

thus: 从而:

if ([[UIApplication sharedApplication] canOpenURL:url]) {
    [[UIApplication sharedApplication] openURL: url];
}

NOTE: 注意:

The above approach should work for iOS 10.x and below (you could check: How to programmatically open the WIFI settings in Objective-C on iOS 10 ). 以上方法适用于iOS 10.x及以下版本(您可以检查: 如何在iOS 10的Objective-C中以编程方式打开WIFI设置 )。 However, the "app-prefs" URL scheme is not supported by Apple! 但是,Apple 支持“ app-prefs” URL方案! prefs URLs are considered as private APIs, the only documented preference URL is the UIApplicationOpenSettingsURLString . prefs URL被视为私有API,唯一记录的首选项URL是UIApplicationOpenSettingsURLString Obviously, is has nothing to do with the used programming language; 显然,与所使用的编程语言无关。 Related: 有关:

Roughly speaking, you are not able to do such a navigation anymore on iOS 11. 粗略地说,您将无法在iOS 11上进行此类导航。

You can use UIApplicationOpenSettingsURLString . 您可以使用UIApplicationOpenSettingsURLString If your application uses location data or bluetooth you will see location and bluetooth settings there. 如果您的应用程序使用位置数据或蓝牙,您将在此处看到位置和蓝牙设置。

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

First: Click on project name >> target>> Info >> url Types >> URL Schemes. 首先:单击项目名称>>目标>>信息>>网址类型>> URL方案。 For example you can see the screenshot. 例如,您可以看到屏幕截图。 在此处输入图片说明

Then use the code: 然后使用代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM