iOS 10+ 跳转系统设置页面.

iOS 10之前, 可以通过

在TargetS -> Info ->URL Types 里面设置URL Schemes 为 prefs,并实现如下代码

UIApplication.shared.open(URL(string:"prefs:root=WIFI")!, options: [:]) { (success) in
        print("RedirectToWifi: \(success)")
}

来设置不同的prefs 跳转到设置的二级页面(例子中是跳转到Wifi设置页)

但是iOS10以后,官方文档表示:

You can use UIApplicationOpenSettingsURLString
to open your own app's settings (this has been available since iOS 8) but any other prefs:
URL is now considered a private API and use will result in app rejection.

意思就是苹果已经不允许app跳到各个设置页面了,只能用

UIApplication.shared.open(URL(string:UIApplicationOpenSettingsURLString)!, options: [:]) { (success) in
        print("RedirectToWifi: \(success)")
}

来跳转到设置页面.

但是如果真的需要跳转到设置页面的话,可以通过如下的方法进行跳转:

    UIApplication.shared.open(URL(string:"App-Prefs:root=WIFI")!, options: [:]) { (success) in
        print("RedirectToWifi: \(success)")
    }

将prefs更改为App-Prefs即可.

But! 不建议这样做哦,

官方文档中说过:
URL is now considered a private API and use will result in app rejection.

虽然是有可能躲过苹果的检测,但是苹果如果发现你这样用了,app上架是有被拒的风险的.

-
That‘s all.

你可能感兴趣的:(iOS 10+ 跳转系统设置页面.)