背景:
给智能设备配置网络,需要直连智能设备发射的wi-fi
目前技术:
ios11后苹果提供 nehotspotconfigurationmanager 类直连周边wi-fi,ios11前只能跳转到系统设置界面手动连接wi-fi
步骤
给开发者中心给 appid 配置连接wi-fi的权限
xcode – build phases – 引入networkextension
xcode – capabilities – hostpot configuration 勾选
代码实现
引入 #import <networkextension/nehotspotconfigurationmanager.h>
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
if (@available(ios 11.0, *)) {
nehotspotconfiguration * hotspotconfig = [[nehotspotconfiguration alloc] initwithssid:@ "deli_l1050adnw_1b0000" ];
// 开始连接 (调用此方法后系统会自动弹窗确认)
[[nehotspotconfigurationmanager sharedmanager] applyconfiguration:hotspotconfig completionhandler:^(nserror * _nullable error) {
nslog(@ "%@" ,error);
if (error && error.code != 13 && error.code != 7) {
} else if (error.code ==7){ //error code = 7 :用户点击了弹框取消按钮
} else { // error code = 13 :已连接
}
}];
} else {
// ios11以下版本逻辑
}
|
以上说的方法不需要去苹果申请权限
注意事项
由于nehotspotconfigurationmanager.h在模拟器上不可用,导入方法为:
?
1
2
3
4
|
#if target_iphone_simulator
#else
#import <networkextension/nehotspotconfigurationmanager.h>
#endif
|
代码逻辑同于注意事项1
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对快网idc的支持。
相关文章
猜你喜欢
- 个人网站服务器域名解析设置指南:从购买到绑定全流程 2025-06-10
- 个人网站搭建:如何挑选具有弹性扩展能力的服务器? 2025-06-10
- 个人服务器网站搭建:如何选择适合自己的建站程序或框架? 2025-06-10
- 64M VPS建站:能否支持高流量网站运行? 2025-06-10
- 64M VPS建站:怎样选择合适的域名和SSL证书? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
2025-05-29 38
-
2025-06-04 43
-
2025-05-29 15
-
asp.net实现上传图片时判断图片的模式GRB或CMYK的方法
2025-05-29 44 -
2025-05-25 67
热门评论