在iOS10更新后,系統(tǒng)設置跳轉被禁用,只能跳轉App設置,但是蘋果又更新了URLscheme,親測不可用。
步驟
第一種方式:
NSString * urlString = @"App-Prefs:root=WIFI";
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:urlString]]) {
if (iOS10) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=WIFI"]];
}
}
第二種方式:
用到了私有API
NSURL*url=[NSURL URLWithString:@"Prefs:root=WIFI"];
Class LSApplicationWorkspace = NSClassFromString(@"LSApplicationWorkspace");
[[LSApplicationWorkspace performSelector:@selector(defaultWorkspace)] performSelector:@selector(openSensitiveURL:withOptions:) withObject:url withObject:nil];
附錄:iOS10之后,其它界面的跳轉
當前iOS10支持的所有跳轉URLSchema
無線局域網 App-Prefs:root=WIFI
藍牙 App-Prefs:root=Bluetooth
蜂窩移動網絡 App-Prefs:root=MOBILE_DATA_SETTINGS_ID
個人熱點 App-Prefs:root=INTERNET_TETHERING
運營商 App-Prefs:root=Carrier
通知 App-Prefs:root=NOTIFICATIONS_ID
通用 App-Prefs:root=General
通用-關于本機 App-Prefs:root=General&path=About
通用-鍵盤 App-Prefs:root=General&path=Keyboard
通用-輔助功能 App-Prefs:root=General&path=ACCESSIBILITY
通用-語言與地區(qū) App-Prefs:root=General&path=INTERNATIONAL
通用-還原 App-Prefs:root=Reset
墻紙 App-Prefs:root=Wallpaper
Siri App-Prefs:root=SIRI
隱私 App-Prefs:root=Privacy
Safari App-Prefs:root=SAFARI
音樂 App-Prefs:root=MUSIC
音樂-均衡器 App-Prefs:root=MUSIC&path=com.apple.Music:EQ
照片與相機 App-Prefs:root=Photos
FaceTime App-Prefs:root=FACETIME
另外,需要在info.plist里的urlTypes添加跳轉urlSchemes

但是通常來說提交審核會遇到這樣的問題:

所以需要做個變化,將prefs字符轉成16進制
如跳轉到設置WiFi界面
NSData *encryptString = [[NSData alloc] initWithBytes:(unsigned char []){0x70,0x72,0x65,0x66,0x73,0x3a,0x72,0x6f,0x6f,0x74,0x3d,0x57,0x49,0x46,0x49} length:15];
NSString *urlString = [[NSString alloc] initWithData:encryptString encoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:urlString];
if ([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)]) {
[[UIApplication sharedApplication] openURL:url options:@{}
completionHandler:^(BOOL success) {
}];
} else {
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
}
}
然后呢,你會收到同樣的拒絕理由。

……
最后的處理的方案是:
1、在需要跳轉的地方加彈框提示用戶自己跳轉
2、跳轉到設置界面
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
最后的結論
浪費了很多時間,得出的重要結論是:
不要跟蘋果粑粑作對,老老實實的聽它的話。