How to programmatically open the WIFI settings in Objective-C on iOS 10

后端 未结 7 1098
失恋的感觉
失恋的感觉 2020-12-17 23:43

The following code works fine on iOS 9, see this post. But it doesn\'t work on iOS 10. How to open WIFI settings programmatically on iOS 10

[[UIApplication s         


        
7条回答
  •  我在风中等你
    2020-12-17 23:55

    Swift 4.2, iOS 12

    It's not longer possible to do that kind of deeplinking with the newer version of iOS. My app was recently rejected for using: "non-public URL scheme", such as: prefs:root=. So I'd say to not waste your time with something that we can't currently do, and simply open the settings.

    This is the function that I'm currently using in my app for it:

    extension UIApplication {
    
        ...
    
        @discardableResult
        static func openAppSetting() -> Bool {
            guard
                let settingsURL = URL(string: UIApplicationOpenSettingsURLString),
                UIApplication.shared.canOpenURL(settingsURL)
                else {
                    return false
            }
    
            UIApplication.shared.open(settingsURL)
            return true
        }
    }
    

    Usage: UIApplication.openAppSetting()

提交回复
热议问题