標籤:
iOS8以上的系統應用可以與設定進行深層的互動,使用者可以根據APP的需要進行對應的許可權的設定。
現在大多數的APP依舊僅僅是彈出一個包含操作指令的警示視窗,如“進入設定>隱私>位置>APP”。其實在高版本的系統中可以直接彈出一個警示視窗,提示內容是自己的APP需要的許可權,點擊確定按鈕可以直接跳到設定中的APP本身的使用權限設定介面。具體的操作方式及代碼在下面。
舉例:
一下是一個日曆相關應用程式的警告代碼,其中包含了為使用者佈建的選項。
func showEventsAcessDeniedAlert() {let alertController = UIAlertController(title: "Sad Face Emoji!",message: "The calendar permission was not authorized. Please enable it in Settings to continue.",preferredStyle: .Alert)let settingsAction = UIAlertAction(title: "Settings", style: .Default) { (alertAction) in// THIS IS WHERE THE MAGIC HAPPENS!!!!if let appSettings = NSURL(string: UIApplicationOpenSettingsURLString) {UIApplication.sharedApplication().openURL(appSettings)}}alertController.addAction(settingsAction)let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)alertController.addAction(cancelAction)presentViewController(alertController, animated: true, completion: nil)}
再次提醒,僅需要添加此代碼到您的APP中就能實現與使用者佈建進行深層連結
if let appSettings = NSURL(string: UIApplicationOpenSettingsURLString) {UIApplication.sharedApplication().openURL(appSettings)}
當使用者點擊開啟設定的時候,他們就很方便的進入了這個介面
只需添加這三行代碼,就能在啟用APP使用許可權這一重要方面提高使用者體驗。讓使用者更改設定中的許可權變得簡單易行。同樣,這也適用於許多其他的應用程式。
文章內容參考自:本文由CocoaChina譯者Kaming翻譯,原文:iOS: You’re Doing Settings Wrong。
iOS 8以上的設定的跳轉