重要!!!!!!
最新更新iOS10
运行iOS10会报错
-canOpenURL: failed for URL: "prefs:root=Bluetooth" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
发现iOS10里使用下面方法已经不行了,查阅各种文档,只有老外说的这么一句话,
You can use UIApplicationOpenSettingsURLString
to open your own app's settings (this has been available since iOS 8) but any other prefs:
URL is now considered a private API and use will result in app rejection.
意思就是苹果已经不允许app跳到各个设置页面了,只能用
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
代替。
(注:openURL这个api也在iOS10上过时,现在openURL:options:CompletionHandler:取代)
如果你的项目曾经使用过下面的方法,想办法改变一下吧。
---------------------------------------分隔线------------------------------------------
如果你的项目在iOS10以下:
最近开发遇到一个很奇怪的问题,就是我们需要在app内部跳转到iOS的蓝牙开启页面。其实很简单就是三行代码的事:
NSURL *url = [NSURL URLWithString:@"prefs:root=Bluetooth"];
if ([[UIApplication sharedApplication]canOpenURL:url]) {
[[UIApplication sharedApplication]openURL:url];
}
开发的时候测试可以,然后甩着不管了。
然后就在五一的前一天,无意间发现,这个canOpenURL返回的竟然是否,然后openURL也打不开系统的蓝牙设置页。顿时蛋疼了起来。排查起来,发现关于所有的prefs:root系统的这种URL都打不开了,卧槽这不扯呢么,为什么好好的就不行了呢,Code的小船就这么翻了吗?
上网查一下吧,baidu上完全没有这方面的信息,只好上StackOverFlow看一下。不得不说这方法还是歪果仁的信息全面,一查一准。
“First configure the URL Schemes in your project. You will find it in Target -> Info -> URL Scheme. click on + button and type prefs in URL Schemes”
加个这么个东西.png也就是说加了URL Schemes:prefs 这么一个玩意就能跳了,果然一跑也能跳了。这不坑爹呢么,为什么突然间就要加这个东西呢。我和同事想了想,只能一句话总结..可能是Xcode7.3的原因吧。
附系统跳转代码
Swift
UIApplication.sharedApplication().openURL(NSURL(string:"prefs:root=General")!)
Objective-c
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=General"]];
prefs:root=General&path=About
prefs:root=General&path=ACCESSIBILITY
prefs:root=AIRPLANE_MODE
prefs:root=General&path=AUTOLOCK
prefs:root=General&path=USAGE/CELLULAR_USAGE
prefs:root=Brightness
prefs:root=Bluetooth
prefs:root=General&path=DATE_AND_TIME
prefs:root=FACETIME
prefs:root=General
prefs:root=General&path=Keyboard
prefs:root=CASTLE
prefs:root=CASTLE&path=STORAGE_AND_BACKUP
prefs:root=General&path=INTERNATIONAL
prefs:root=LOCATION_SERVICES
prefs:root=ACCOUNT_SETTINGS
prefs:root=MUSIC
prefs:root=MUSIC&path=EQ
prefs:root=MUSIC&path=VolumeLimit
prefs:root=General&path=Network
prefs:root=NIKE_PLUS_IPOD
prefs:root=NOTES
prefs:root=NOTIFICATIONS_ID
prefs:root=Phone
prefs:root=Photos
prefs:root=General&path=ManagedConfigurationList
prefs:root=General&path=Reset
prefs:root=Sounds&path=Ringtone
prefs:root=Safari
prefs:root=General&path=Assistant
prefs:root=Sounds
prefs:root=General&path=SOFTWARE_UPDATE_LINK
prefs:root=STORE
prefs:root=TWITTER
prefs:root=FACEBOOK
prefs:root=General&path=USAGE prefs:root=VIDEO
prefs:root=General&path=Network/VPN
prefs:root=Wallpaper
prefs:root=WIFI
prefs:root=INTERNET_TETHERING
网友评论
Wifi的亲测,可以
```
//注意首字母改成了大写,prefs->Prefs
NSURL*url=[NSURL URLWithString:@"Prefs:root=General&path=About"];
Class LSApplicationWorkspace = NSClassFromString(@"LSApplicationWorkspace");
[[LSApplicationWorkspace performSelector:@selector(defaultWorkspace)] performSelector:@selector(openSensitiveURL:withOptions:) withObject:url withObject:nil];
```
用self.extensionContext.open(NSURL(string: "Prefs:root=WIFI
可以实现