iOS開發(fā)APP跳轉(zhuǎn)到設(shè)置或系統(tǒng)頁面詳解
iOS10以前
- 打開設(shè)置應(yīng)用:
UIApplication.openSettingsURLString
- 打開通用設(shè)置:
App-Prefs:root=General
- 打開關(guān)于本機:
App-Prefs:root=General&path=About
- 打開軟件更新:
App-Prefs:root=General&path=SOFTWARE_UPDATE_LINK
- 打開網(wǎng)絡(luò)設(shè)置:
App-Prefs:root=General&path=Network
- 打開Wi-Fi設(shè)置:
App-Prefs:root=WIFI
- 打開藍牙設(shè)置:
App-Prefs:root=Bluetooth
- 打開移動數(shù)據(jù)設(shè)置:
App-Prefs:root=MOBILE_DATA_SETTINGS_ID
- 打開運營商設(shè)置:
App-Prefs:root=Carrier
- 打開個人熱點設(shè)置:
App-Prefs:root=INTERNET_TETHERING
- 打開聲音和振動設(shè)置:
App-Prefs:root=Sounds
- 打開顯示和亮度設(shè)置:
App-Prefs:root=Brightness
- 打開壁紙設(shè)置:
App-Prefs:root=Wallpaper
- 打開Siri設(shè)置:
App-Prefs:root=SIRI
- 打開Touch ID和密碼設(shè)置:
App-Prefs:root=TOUCHID_PASSCODE
- 打開Face ID和密碼設(shè)置:
App-Prefs:root=PASSCODE
- 打開隱私設(shè)置:
App-Prefs:root=Privacy
- 打開位置服務(wù)設(shè)置:
App-Prefs:root=LOCATION_SERVICES
- 打開日期和時間設(shè)置:
App-Prefs:root=General&path=DATE_AND_TIME
- 打開iCloud設(shè)置:
App-Prefs:root=CASTLE
- 打開iCloud存儲空間設(shè)置:
App-Prefs:root=CASTLE&path=STORAGE_AND_BACKUP
- 代碼跳轉(zhuǎn)到應(yīng)用設(shè)置頁面
if let settingsURL = URL(string: UIApplication.openSettingsURLString) { UIApplication.shared.open(settingsURL) }
- 代碼跳轉(zhuǎn)到Siri設(shè)置頁面
if let siriSettingsURL = URL(string: "App-Prefs:root=SIRI") { UIApplication.shared.open(siriSettingsURL) }
在 iOS 10 之前,可以使用 App-Prefs: 開頭的 URL Scheme 來直接跳轉(zhuǎn)到系統(tǒng)設(shè)置的各個頁面,而在 iOS 10 開始,Apple 對此進行了限制,只允許跳轉(zhuǎn)到設(shè)置應(yīng)用的主頁面或者一些帶有固定路徑的頁面,例如通用設(shè)置、安全設(shè)置等等,這些固定路徑的頁面是可以通過 URL Scheme 來跳轉(zhuǎn)到的。但是網(wǎng)絡(luò)設(shè)置等其他設(shè)置頁面沒有固定路徑,所以不能直接通過 URL Scheme 來跳轉(zhuǎn),需要用戶手動從設(shè)置應(yīng)用中找到相應(yīng)的頁面。
在iOS10以后的系統(tǒng)中
定位到特定應(yīng)用程序或功能的頁面:
- App Store:
itms-apps://
- 聯(lián)系人:
contacts://
- FaceTime:
facetime://
- 郵件:
mailto://
- Google 地圖:
comgooglemaps://
- Apple 地圖:
http://maps.apple.com/
- 照片:
photos-redirect://
- 電話撥號:
tel://
- 短信:
sms://
- 日歷:
calshow://
- 音樂:
music://
- Apple 音樂:
music://
- 視頻:
videos://或video://
- 錢包:
shoebox://
- 設(shè)置:
App-Prefs://
或App-Settings://
- FaceTime:
facetime://
或facetime-audio://
電話和短信:可以使用tel:
或sms:
開頭的URL撥打電話或發(fā)送短信。例如,可以使用tel://1234567890
打電話,或使用sms://1234567890
發(fā)送短信。
郵件:可以使用mailto:
開頭的URL使用郵件客戶端發(fā)送電子郵件。例如,可以使用mailto:example@example.com
發(fā)送電子郵件。
iTunes應(yīng)用商店:可以使用itms://
或itms-apps://
開頭的URL跳轉(zhuǎn)到iTunes應(yīng)用商店。例如,可以使用itms-apps://itunes.apple.com/us/app/your-app-name/id1234567890?mt=8
查找您的應(yīng)用。
要跳轉(zhuǎn)到 iOS 中系統(tǒng)相片,可以使用以下代碼:
if let url = URL(string: "photos-redirect://") { if UIApplication.shared.canOpenURL(url) { UIApplication.shared.open(url, options: [:], completionHandler: nil) } }
如果您想直接跳轉(zhuǎn)到特定相冊中,請修改URL,例如:
if let url = URL(string: "photos-redirect://") { if UIApplication.shared.canOpenURL(url) { let albumName = "HeHeMyAlbum" let encodedAlbumName = albumName.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)! let url = URL(string: "photos-redirect://album/\(encodedAlbumName)")! UIApplication.shared.open(url, options: [:], completionHandler: nil) } }
此代碼將打開名為"HeHeMyAlbum"的相冊頁面。要在您的應(yīng)用程序中查找可用的相冊名稱,請使用 fetchAssetCollections
方法來獲取所有相冊的列表,然后在結(jié)果中查找相應(yīng)的名稱。
取所有相冊的列表,你可以使用 PHAssetCollection
類的 fetchAll
方法。以下是使用 Swift 的示例代碼:
import Photos let fetchOptions = PHFetchOptions() fetchOptions.sortDescriptors = [NSSortDescriptor(key: "localizedTitle", ascending: true)] let collections = PHAssetCollection.fetchAssetCollections(with: .album, subtype: .any, options: fetchOptions) collections.enumerateObjects { collection, index, stop in print(collection.localizedTitle) }
此代碼使用 fetchAssetCollections
方法獲取所有相冊的列表,并對結(jié)果進行排序。然后,它迭代每個相冊,并使用 localizedTitle
屬性打印出本地化標(biāo)題。通過更改 enumerateObjects
中的代碼,您可以執(zhí)行您想要的其他操作,例如將相冊列表顯示在用戶界面中。
以上就是iOS開發(fā)APP跳轉(zhuǎn)到設(shè)置或系統(tǒng)頁面詳解的詳細內(nèi)容,更多關(guān)于iOS APP跳轉(zhuǎn)設(shè)置系統(tǒng)頁面的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
如何為Xcode添加刪除整行、復(fù)制整行及在下方新建一行快捷鍵詳解
xcode是蘋果公司向開發(fā)人員提供的集成開發(fā)環(huán)境,開發(fā)者們經(jīng)常會使用到,下面這篇文章主要給大家介紹了關(guān)于如何為Xcode添加刪除整行、復(fù)制整行及在下方新建一行快捷鍵的相關(guān)資料,需要的朋友可以參考下。2018-04-04