iOS跳转到系统设置界面

2018-02-06  本文已影响62人  沈正方

参考:IOS应用内跳转到系统设置
考虑到目前基本上不需要考虑iOS8之前的系统了,所以本文只介绍iOS8+的情况

主要步骤

1. 设置URL Scheme
进入info.plist文件,设置URL Types属性

image.png

2. 创建跳转路径url
UIApplicationOpenSettingsURLString:用来创建跳转路径url的string

Used to create a URL that you can pass to the open<wbr>URL(_:)method. When you open the URL built from this string, the system launches the Settings app and displays the app’s custom settings, if it has any.
适用版本iOS 8.0+ / tvOS 9.0+

let url = URL(string: UIApplicationOpenSettingsURLString)

3. 执行跳转
openURL(_:):(iOS 2 ~ iOS 10)
open(_:options:completionHandler:):(iOS 10 ~)

UIApplication.shared.openURL(url)
or
UIApplication.shared.open(URL(string: url options: [:], completionHandler: { (granted) in
       if granted {
              print("jump success")
       } else {
              print("jump failure")
       }      
 })

Tips:理论上以上代码的跳转结果是

相关代码前往GitHub,如果觉得有收获,留个小星星感激不尽…

上一篇下一篇

猜你喜欢

热点阅读