Open Wifi Settings by “prefs:root=WIFI” failed in iOS 10

情到浓时终转凉″ 提交于 2019-11-27 21:13:02

问题


I was using prefs:root=WIFI url scheme in my app with prefs entered in info.plist to open directly the iOS settings application in Wi-Fi settings and it was working great on iOS 9 but it does not work anymore on iOS 10.

Does anyone know if this is just a regression in the first developer preview or the way to open Wi-Fi settings has changed in iOS 10 or it is not allowed anymore?


回答1:


Just so it's explicit: Apple does not allow this. It's possible your app will make it through anyway, but this is the same as using any other undocumented API.

Here is the full list of supported Apple URL schemes.

Here's a thread where Apple confirms that "any Apple URL schemes that are not officially documented should be considered private API."




回答2:


SWIFT 3.0:- working in iOS 10

@IBAction func openWifiSetting(_ sender: AnyObject) {
    let url = URL(string: "App-Prefs:root=WIFI") //for WIFI setting app
    UIApplication.shared.openURL(url!)
}



回答3:


My app is also using that api. Unfortunately apple disable this on iOS 10. Here's my solution: below iOS 10, it can still open Setting App. on iOS 10, it will go to a subpage(Cellular Data access) of Setting App, you can back to setting page by one click. I decide to keep it. because it's still convenient than user manually open Setting App.

NSURL *url = [NSURL URLWithString:@"prefs:root=WIFI"];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
    [[UIApplication sharedApplication] openURL:url];
} else {
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}



回答4:


try this for objective c in iOS 10

NSURL *url = [NSURL URLWithString:@"prefs:root=WIFI"];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
   [[UIApplication sharedApplication] openURL:url];
} else {
   [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=WIFI"]];
}



回答5:


Using "App-Prefs:root" instead of "prefs:root"




回答6:


iOS 10, to open your apps settings:

if let settingsURL = URL(string: UIApplicationOpenSettingsURLString) {  
                UIApplication.shared.openURL(settingsURL)
          }



回答7:


This works fine on iOS 10,

Go to Targets --> (Application) --> Info --> URL Types --> +

In the URL Schemes write

prefs

Then Call,

- (void)openWifiSettings
{
    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"prefs:root=WIFI"]]) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=WIFI"]];
    } else {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=WIFI"]];
    }
}


来源:https://stackoverflow.com/questions/39782510/open-wifi-settings-by-prefsroot-wifi-failed-in-ios-10

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!