iOS11实现App内自动连接Wi-Fi的方法

2025-05-29 0 97

背景:

给智能设备配置网络,需要直连智能设备发射的wi-fi

目前技术:

ios11后苹果提供 nehotspotconfigurationmanager 类直连周边wi-fi,ios11前只能跳转到系统设置界面手动连接wi-fi

步骤

给开发者中心给 appid 配置连接wi-fi的权限

iOS11实现App内自动连接Wi-Fi的方法

xcode – build phases – 引入networkextension

iOS11实现App内自动连接Wi-Fi的方法

xcode – capabilities – hostpot configuration 勾选

iOS11实现App内自动连接Wi-Fi的方法

代码实现

引入 #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的支持。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 iOS11实现App内自动连接Wi-Fi的方法 https://www.kuaiidc.com/89189.html

相关文章

发表评论
暂无评论