1. 程式人生 > >iOS 花五分鐘看完這篇文章,學會跳轉指定App的設定頁面(相容iOS10)

iOS 花五分鐘看完這篇文章,學會跳轉指定App的設定頁面(相容iOS10)

iOS對於App的許可權管理有了很大的進步,但是當自己的App被禁止通知或者禁止聯網使用藍芽等情況發生時,怎麼引導使用者去設定頁面開啟這些許可權,是很多產品需要的功能。

這邊文章都是以跳轉設定推送頁面為例,更多的URL在文章末尾。

跳轉設定頁面有個分水嶺,iOS10之前和之後有些差別,當然他們也有共性。

首先宣告要使用到的URL scheme,這一步必須做,仔細看下面一張圖


這裡的prefs代表系統的設定,如果不新增這個,是無論如何也跳不過去的,不管iOS的系統版本是什麼,這裡都是prefs

iOS10之前:

直接上程式碼:

NSString * idf = [NSBundle mainBundle].bundleIdentifier;
NSString * string = [NSString stringWithFormat:@"prefs:root=NOTIFICATIONS_ID&path=%@", idf];
NSURL * url = [NSURL URLWithString:string];
[[UIApplication sharedApplication] openURL:url];

這裡的idf代表的是跳轉到自己應用的推送設定頁面。

iOS10之後:

NSString * idf = [NSBundle mainBundle].bundleIdentifier;
NSString * string = [NSString stringWithFormat:@"App-Prefs:root=NOTIFICATIONS_ID&path=%@", idf];
NSURL * url = [NSURL URLWithString:string];
[[UIApplication sharedApplication] openURL:url];

只是把prefs:root改成App-Prefs:root即可

更多URL:

iOS10之前:

  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    //開啟Brightness(亮度)設定介面
  prefs:root=Bluetooth    //開啟藍芽設定
  prefs:root=General&path=DATE_AND_TIME    //日期與時間設定
  prefs:root=FACETIME    //開啟FaceTime設定
  prefs:root=General    //開啟通用設定
  prefs:root=General&path=Keyboard    //開啟鍵盤設定
  prefs:root=CASTLE    //開啟iClound設定
  prefs:root=CASTLE&path=STORAGE_AND_BACKUP    //開啟iCloud下的儲存空間
  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    //開啟設定下的safari設定
  prefs:root=General&path=Assistant    //開啟siri不成功
  prefs:root=Sounds    //開啟設定下的聲音設定
  prefs:root=General&path=SOFTWARE_UPDATE_LINK    //開啟通用下的軟體更新
  prefs:root=STORE    //開啟通用下的iTounes Store和App Store設定
  prefs:root=TWITTER    //開啟設定下的twitter設定
  prefs:root=FACEBOOK    //開啟設定下的Facebook設定
  prefs:root=General&path=USAGE    //開啟通用下的用量
  prefs:root=VIDEO    
  prefs:root=General&path=Network/VPN        //開啟通用下的vpn設定
  prefs:root=Wallpaper    //開啟設定下的牆紙設定
  prefs:root=WIFI    //開啟wifi設定
  prefs:root=INTERNET_TETHERING

iOS10之後:

設定頁面 App-Prefs:root
無線區域網 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
通用-語言與地區 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