iOS App 內跳轉到手機系統設定頁面

來源:互聯網
上載者:User

標籤:跳轉   time   tor   service   strong   network   三種方式   模式   photo   

  在iOS開發中,有時會有跳轉系統設定介面的需求,例如提示使用者開啟提醒使用者開啟推送或者位置許可權等。

在iOS6之後,第三方應用需要跳轉系統設定介面,需要在URL type中添加一個Prefs值,如:

注意:設定跳轉有三種方式,每一種的使用情境都不同。 並且你在跳轉到系統中自己應用下面設定的時候,

你的應用要提前至少申請了某一個許可權,如通知,定位等。否則,會引起崩潰。

  • 方式一:prefs:root=某項服務
  • 方式二:prefs:root=bundleID
  • 方式三: UIApplicationOpenSettingsURLString

下面具體的說下跳轉的實現:

  1. 跳轉方法:
  2. 當iOS系統版本 < iOS 10.0 時NSURL *url= [NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"];if( [[UIApplication sharedApplication]canOpenURL:url] ) { [[UIApplication sharedApplication]openURL:url];}當iOS系統版本 >=iOS 10.0 時if( [[UIApplication sharedApplication]canOpenURL:url] ) {[[UIApplication sharedApplication]openURL:url options:@{}completionHandler:^(BOOL  success) {}];}

     

        2.跳轉到具體的位置:(不同的方式具體說明)

  • 方式一:

    當 iOS系統版本 <= iOS7時 , 只能跳轉到 系統設定頁面:

            舉例說明:跳轉到: 隱私-定位服務。  NSURL *url= [NSURL URLWithString:@"prefs:root=LOCATION_SERVICES

  prefs:root=某項服務
  系統設定:prefs:root=INTERNET_TETHERING  WIFI設定:prefs:root=WIFI  藍芽設定:prefs:root=Bluetooth  系統通知:prefs:root=NOTIFICATIONS_ID  通用設定:prefs:root=General  顯示設定:prefs:root=DISPLAY&BRIGHTNESS  壁紙設定:prefs:root=Wallpaper  聲音設定:prefs:root=Sounds  隱私權設定:prefs:root=privacy  蜂窩網路:prefs:root=MOBILE_DATA_SETTINGS_ID  音樂:prefs:root=MUSIC
  相簿":prefs:root=Photos
  APP Store:prefs:root=STORE 

  Notes:prefs:root=NOTES

  Safari:prefs:root=Safari
  
這種跳轉方式,都是跳轉到系統的設定介面。
  • 方式二 :

    當 iOS系統版本 >= iOS8 ,支援跳轉到第三方應用的設定介面中

    使用prefs:root=bundleID ,bundleID是你第三方應用工程的唯一ID

    局限性:只支援iOS8,iOS9系統,在iOS10系統上,不會跳轉。

    在iOS7系統上,僅僅只是跳轉到設定應用,不推薦使用。

    如果需要繼續向項目內層進行跳轉,可以通過添加path路徑的方式,如下:

     關於本機: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

     鍵盤設定:prefs:root=General&path=Keyboard

     聲音設定:prefs:root=Sounds

     隱私權設定:prefs:root=privacy

     APP Store:prefs:root=STORE

     還原設定:prefs:root=General&path=Reset

     應用通知:prefs:root=NOTIFICATIONS_ID&path=應用的boundleId

     定位:prefs:root=LOCATION_SERVICES

     蜂窩網路:prefs:root=MOBILE_DATA_SETTINGS_ID

     VPN — prefs:root=General&path=Network/VPN

     Wi-Fi:prefs:root=WIFI

     定位服務:prefs:root=LOCATION_SERVICES

     個人熱點:prefs:root=INTERNET_TETHERING

     協助工具功能:prefs:root=General&path=ACCESSIBILITY

     飛航模式:prefs:root=AIRPLANE_MODE

     鎖定:prefs:root=General&path=AUTOLOCK

     亮度:prefs:root=Brightness

     藍芽:prefs:root=General&path=Bluetooth

     設定:prefs:root=General

     Network — prefs:root=General&path=Network

     Notes — prefs:root=NOTES

     Photos — prefs:root=Photos

     Sounds — prefs:root=Sounds

     Software Update — prefs:root=General&path=SOFTWARE_UPDATE_LINK

     Store — prefs:root=STORE

  • 方式三

     當 iOS系統版本 >= iOS8,支援跳轉到自己應用設定,不支援跳轉到系統設定。

    NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];

    UIApplicationOpenSettingsURLString是在iOS8上才提供的,支援iOS8,iOS9,iOS10系統,推薦使用。

            而 prefs:root=bundleID和 prefs:root=服務 都將不起作用。

iOS App 內跳轉到手機系統設定頁面

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.