如何以编程方式在iOS 10上的Objective-C中打开WIFI设置 [英] How to programmatically open the WIFI settings in Objective-C on iOS 10
本文介绍了如何以编程方式在iOS 10上的Objective-C中打开WIFI设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码在iOS 9上运行正常,请参阅
然后添加以下代码,
- (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]];
}
}
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 sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=WIFI"]];
解决方案
This works fine on iOS 10,
Go to Targets --> (Application) --> Info --> URL Types --> +
In the URL Schemes
write
prefs
See the image,
Then add the following code,
-(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"]];
}
}
这篇关于如何以编程方式在iOS 10上的Objective-C中打开WIFI设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文