您现在的位置: IOS教程網 >> IOS系統 >  >> iOS 程式開發 >> iOS 開發綜合

iOS 開發:應用內跳轉到系統「設定」的方法

編輯:iOS 開發綜合

應用內跳轉到系統「設定」頁面是常見需求,但不同 iOS 版本的做法有所差異。以下整理各版本的實作方式。

iOS 5.1 之前:透過 URL Scheme

在 iOS 5.1 之前,可以透過 URL Scheme 的方式開啟內建的 Settings(注意:此方法在 iOS 5.1 之後已無法使用):

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];

以下是內建 Settings 的各種 URL Scheme:

About           — prefs:root=General&path=About
Accessibility   — prefs:root=General&path=ACCESSIBILITY
Airplane Mode   — prefs:root=AIRPLANE_MODE
Auto-Lock       — prefs:root=General&path=AUTOLOCK
Brightness      — prefs:root=Brightness
Bluetooth       — prefs:root=General&path=Bluetooth
Date & Time     — prefs:root=General&path=DATE_AND_TIME
FaceTime        — prefs:root=FACETIME
General         — prefs:root=General
Keyboard        — prefs:root=General&path=Keyboard
iCloud          — prefs:root=CASTLE
iCloud Backup   — prefs:root=CASTLE&path=STORAGE_AND_BACKUP
Location        — prefs:root=LOCATION_SERVICES
Music           — prefs:root=MUSIC
Network         — prefs:root=General&path=Network
Notification    — prefs:root=NOTIFICATIONS_ID
Phone           — prefs:root=Phone
Photos          — prefs:root=Photos
Reset           — prefs:root=General&path=Reset
Safari          — prefs:root=Safari
Siri            — prefs:root=General&path=Assistant
Sounds          — prefs:root=Sounds
Software Update — prefs:root=General&path=SOFTWARE_UPDATE_LINK
Store           — prefs:root=STORE
Twitter         — prefs:root=TWITTER
VPN             — prefs:root=General&path=Network/VPN
Wallpaper       — prefs:root=Wallpaper
Wi-Fi           — prefs:root=WIFI

iOS 8:使用官方提供的 URL

在 iOS 8 版本,蘋果提供了官方的常量 UIApplicationOpenSettingsURLString,可直接跳轉到當前應用的設定頁:

NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
    [[UIApplication sharedApplication] openURL:url];
}

需要特別注意的是:從 iOS 5.1 到 iOS 7 之間,Apple 基於安全考量封鎖了 prefs: 這類私有 URL Scheme,因此無法直接跳轉到系統設定的任意頁面;直到 iOS 8 才重新開放了跳轉到「本應用設定頁」的官方途徑。呼籲開發者在實作時依據目標系統版本選擇合適的方案。

  1. 上一篇文章:
  2. 下一篇文章:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © IOS教程網 All Rights Reserved