在 iOS 開發(fā)中,經(jīng)常會遇到有跳轉(zhuǎn)至系統(tǒng)設(shè)置相關(guān)界面的需求,例如提示用戶開啟藍牙或者 WiFi 等功能提示操作,提醒用戶打開推送或者位置權(quán)限等.
在 iOS 6之后,第三方應(yīng)用需要跳轉(zhuǎn)系統(tǒng)設(shè)置界面則需要在 URL type 中添加一個 prefs 值.
跳轉(zhuǎn)系統(tǒng)設(shè)置根目錄中的項目使用如下方法:
_array = @[
@{@"系統(tǒng)設(shè)置":@"prefs:root=INTERNET_TETHERING"},
@{@"WIFI設(shè)置":@"prefs:root=WIFI"},
@{@"藍牙設(shè)置":@"prefs:root=Bluetooth"},
@{@"系統(tǒng)通知":@"prefs:root=NOTIFICATIONS_ID"},
@{@"通用設(shè)置":@"prefs:root=General"},
@{@"顯示設(shè)置":@"prefs:root=DISPLAY&BRIGHTNESS"},
@{@"壁紙設(shè)置":@"prefs:root=Wallpaper"},
@{@"聲音設(shè)置":@"prefs:root=Sounds"},
@{@"隱私設(shè)置":@"prefs:root=privacy"},
@{@"APP Store":@"prefs:root=STORE"},
@{@"Notes":@"prefs:root=NOTES"},
@{@"Safari":@"prefs:root=Safari"},
@{@"Music":@"prefs:root=MUSIC"},
@{@"photo":@"prefs:root=Photos"}
];
NSURL * url = [NSURL URLWithString:[_array[index] allValues].firstObject];
[[UIApplication sharedApplication]openURL:url];
如果要跳轉(zhuǎn)至第三方應(yīng)用的設(shè)置界面中,則使用 prefs:root = boundleId 的方式.?
注:boundleId 是第三方應(yīng)用的 boundleId.
如果需要繼續(xù)向項目內(nèi)層進行跳轉(zhuǎn),則可以通過添加 path 路徑的方式,具體如下:
_array = @[
@{@"關(guān)于本機":@"prefs:root=General&path=About"},
@{@"軟件升級":@"prefs:root=General&path=SOFTWARE_UPDATE_LINK"},
@{@"日期時間":@"prefs:root=General&path=DATE_AND_TIME"},
@{@"Accessibility":@"prefs:root=General&path=ACCESSIBILITY"},
@{@"鍵盤設(shè)置":@"prefs:root=General&path=Keyboard"},
@{@"VPN":@"prefs:root=General&path=VPN"},
@{@"壁紙設(shè)置":@"prefs:root=Wallpaper"},
@{@"聲音設(shè)置":@"prefs:root=Sounds"},
@{@"隱私設(shè)置":@"prefs:root=privacy"},
@{@"APP Store":@"prefs:root=STORE"},
@{@"還原設(shè)置":@"prefs:root=General&path=Reset"},
@{@"應(yīng)用通知":@"prefs:root=NOTIFICATIONS_ID&path=應(yīng)用的boundleId"}
];
代碼示例如下:
NSURL* url = [NSURLURLWithString:@"prefs:root=privacy"];
[[UIApplicationsharedApplication]openURL:url];