我无法获得" prefs"在iOS 10中工作的URL方案。
它设置正确,因为相同的应用程序在iOS 9上正常工作。
这是一个错误还是重命名/删除了?
代码:
NSURL *url = [NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"];
if (![[UIApplication sharedApplication]canOpenURL:url]) {
[[UIApplication sharedApplication]openURL:url];
}
答案 0 :(得分:2)
iOS 10中的新方法:
//Objective-C
- (void)openURL:(NSURL*)url options:(NSDictionary<NSString *, id> *)options
completionHandler:(void (^ __nullable)(BOOL success))completion
// Swift
open func open(_ url: URL, options: [String : Any] = [:],
completionHandler completion: (@escaping (Bool) -> Swift.Void)? = nil)
使用iOS 10打开网址
// Objective-C
UIApplication *application = [UIApplication sharedApplication];
[application openURL:URL options:@{} completionHandler:nil];
// Swift
UIApplication.shared.open(url, options: [:], completionHandler: nil)
有关详细信息,请参阅this link
答案 1 :(得分:2)
要用prefs
替换App-Prefs
,这是我的Swift帮助方法,以支持iOS 10及更低版本,在iOS 9及更高版本上测试10
class Helper {
static func openLocationSettings() {
if #available(iOS 10.0, *) {
openSettings(url: "App-Prefs:root=Privacy&path=LOCATION")
} else {
openSettings(url: "prefs:root=LOCATION_SERVICES")
}
}
static func openSettings(url: String) {
guard let settingsUrl = URL(string: url), UIApplication.shared.canOpenURL(settingsUrl) else { return }
if #available(iOS 10.0, *) {
UIApplication.shared.open(settingsUrl)
} else {
UIApplication.shared.openURL(settingsUrl)
}
}
}
示例1 打开位置设置:
Helper.openLocationSettings()
示例2 打开应用程序设置:
Helper.openSettings(url: UIApplicationOpenSettingsURLString)
答案 2 :(得分:0)
我建议首先验证方法可用性,然后使用适当的方法。
if ([application respondsToSelector:@selector(openURL:options:completionHandler:)])
{
[application openURL:URL options:@{}
completionHandler:^(BOOL success) {
NSLog(@"Open URL Scheme %@: %d",scheme,success);
}];
}
else
{
BOOL success = [application openURL:URL];
NSLog(@"Open URL Scheme %@: %d",scheme,success);
}
希望这有帮助。
答案 3 :(得分:0)
将您的方案添加到您的plist作为您的一个URLSchemes
答案 4 :(得分:0)
b = [a[i:i+2] for i in range(0, len(a), 2)] # ['10', 'F8', '00', ...
c = [int(i, 16) for i in b] # [16, 248, 0, ...
d = 256 - sum(c) % 256 # 0x30
e = hex(d)[2:] # '30'
适用于iOS 10以下...因此选中了prefs:root=LOCATION_SERVICES
和UIApplicationOpenSettingsURLString
。两者都在为我工作....得到了@Rajan Balan的暗示。
App-Prefs:root=Privacy&path=LOCATION
哪里
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]]) {
if(SYSTEM_VERSION_GREATER_THAN(@"10")) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=Privacy&path=LOCATION"]];
// Below code is also working in iOS 10 to open location services
// [[UIApplication sharedApplication] openURL:[NSURL URLWithString: UIApplicationOpenSettingsURLString]];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];
}
}