【发布时间】:2016-10-05 20:48:01
【问题描述】:
【问题讨论】:
标签: ios objective-c location-services
【问题讨论】:
标签: ios objective-c location-services
我已经尝试了以上所有答案,它在 iOS11 上不起作用..它只是打开设置页面而不是应用程序设置..最后这工作..
UIApplication.shared.open(URL(string:UIApplicationOpenSettingsURLString)!)
Swift 4.2:
UIApplication.shared.open(URL(string:UIApplication.openSettingsURLString)!)
参考:https://developer.apple.com/documentation/uikit/uiapplicationopensettingsurlstring?language=swift
【讨论】:
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)
}
【讨论】:
您可以像使用下面的代码一样直接打开它,
但首先在 Info.plist 的 URL Type Like 中设置URL Schemes:
然后在特定事件写下一行:
在目标 - C:
[[UIApplication sharedApplication] openURL:
[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];
在 Swift 中:
UIApplication.sharedApplication().openURL(NSURL(string: "prefs:root=LOCATION_SERVICES")!)
希望这会对你有所帮助。
【讨论】:
URL(string: "App-prefs:root=LOCATION_SERVICES") 仍然可以正常工作...
??
你想安全吗?使用UIApplicationOpenSettingsURLString,它将打开应用设置,没有深层链接。
正如许多 sub cmets 所说,使用 App-prefs 您的应用将被拒绝。
https://github.com/mauron85/cordova-plugin-background-geolocation/issues/394
【讨论】:
【讨论】:
第一:
添加网址
转到项目设置 --> 信息 --> URL 类型 --> 添加新的 URL 方案
见下图:
第二个:
使用以下代码打开位置设置:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];
【讨论】:
App-Prefs:root=Privacy&path=LOCATION 为我工作。
如果您设置了 locationManager.startUpdatingLocation() 并且您已在 iphone 上禁用,它会自动向您显示一个 alertView,其中包含打开和激活位置的选项。
【讨论】:
startUpdatingLocation() 向我展示了一个标准对话框来导航到定位服务设置。它导航到系统范围的位置服务设置!但它只是在我第一次调用它时才这样做。对此有什么想法吗?
斯威夫特 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)
}
【讨论】:
实际上有更简单的解决方案。它会显示您的应用设置以及定位服务/相机访问等:
func showUserSettings() {
guard let urlGeneral = URL(string: UIApplicationOpenSettingsURLString) else {
return
}
UIApplication.shared.open(urlGeneral)
}
【讨论】:
将prefs添加为url类型后,使用以下代码直接进入应用程序的位置设置。
if let url = URL(string: "App-prefs:root=LOCATION_SERVICES") {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
【讨论】: