重要9瘐铩!4健<料啊!!
最新更新iOS10
運(yùn)行iOS10會報(bào)錯
-canOpenURL: failed for URL: "prefs:root=Bluetooth" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
發(fā)現(xiàn)iOS10里使用下面方法已經(jīng)不行了鳞绕,查閱各種文檔失仁,只有老外說的這么一句話,
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.
意思就是蘋果已經(jīng)不允許app跳到各個設(shè)置頁面了们何,只能用
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
代替萄焦。
(注:openURL這個api也在iOS10上過時,現(xiàn)在openURL:options:CompletionHandler:取代)
如果你的項(xiàng)目曾經(jīng)使用過下面的方法冤竹,想辦法改變一下吧拂封。
---------------------------------------分隔線------------------------------------------
如果你的項(xiàng)目在iOS10以下:
最近開發(fā)遇到一個很奇怪的問題,就是我們需要在app內(nèi)部跳轉(zhuǎn)到iOS的藍(lán)牙開啟頁面鹦蠕。其實(shí)很簡單就是三行代碼的事:
NSURL *url = [NSURL URLWithString:@"prefs:root=Bluetooth"];
if ([[UIApplication sharedApplication]canOpenURL:url]) {
[[UIApplication sharedApplication]openURL:url];
}
開發(fā)的時候測試可以冒签,然后甩著不管了。
然后就在五一的前一天钟病,無意間發(fā)現(xiàn)萧恕,這個canOpenURL返回的竟然是否,然后openURL也打不開系統(tǒng)的藍(lán)牙設(shè)置頁肠阱。頓時蛋疼了起來票唆。排查起來,發(fā)現(xiàn)關(guān)于所有的prefs:root系統(tǒng)的這種URL都打不開了屹徘,臥槽這不扯呢么走趋,為什么好好的就不行了呢,Code的小船就這么翻了嗎缘回?
上網(wǎng)查一下吧吆视,baidu上完全沒有這方面的信息,只好上StackOverFlow看一下酥宴。不得不說這方法還是歪果仁的信息全面啦吧,一查一準(zhǔn)。
“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”
也就是說加了URL Schemes:prefs 這么一個玩意就能跳了拙寡,果然一跑也能跳了授滓。這不坑爹呢么,為什么突然間就要加這個東西呢肆糕。我和同事想了想般堆,只能一句話總結(jié)..可能是Xcode7.3的原因吧。
附系統(tǒng)跳轉(zhuǎn)代碼
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