iOS自动连接已知Wi-Fi功能的实现

首先需要在配置文件申请的时候将hotspot勾选上,之后还要在x-code里添加对应的配置,由于我们并没有用到获取设备周边Wi-Fi的功能,所以就没申请相关权限

相关连接Wi-Fi代码如下:

#import <NetworkExtension/NetworkExtension.h>

//无密码初始化

NEHotspotConfiguration *hotspotConfig = \[NEHotspotConfiguration allocinitWithSSID:@"Wi-Fi名"];

//有密码初始化

NEHotspotConfiguration *hotspotConfig = \[NEHotspotConfiguration allocinitWithSSID:@"Wi-Fi名" passphrase:@"密码" isWEP:NO];

\[NEHotspotConfigurationManager sharedManagerapplyConfiguration:hotspotConfig completionHandler:^(NSError * _Nullable error) {

if (error && error.code != 13 && error.code != 7) {

NSLog(@"加入失败");

}else if(error.code ==7){

NSLog(@"已取消");

}else{

NSLog(@"已连接");

}

}];

\[NEHotspotConfigurationManager sharedManager getConfiguredSSIDsWithCompletionHandler:^(NSArray<NSString *> * array) {

for (NSString * str in array) {

NSLog(@"加入过的WiFi:%@",str);

}

}];

相关推荐
2501_9159184121 分钟前
iOS 真机调试工具推荐,安装运行、性能分析有哪些工具
ide·vscode·ios·objective-c·个人开发·swift·敏捷流程
游戏开发爱好者810 小时前
带签名时间戳接口的重放与压力测试实战,用动态值在发送前现算签名
网络协议·计算机网络·网络安全·ios·adb·https·压力测试
2501_916007471 天前
申请 iOS 推送证书并配置 APNs 群发推送教程
android·ios·小程序·https·uni-app·iphone·webview
weixin_403810131 天前
iOS自动化脚本怎么避免风控?无屏幕镜像截图原理详解
ios·自动化·跨境电商·苹果群控·苹果投屏·多媒体运营
wangruofeng1 天前
3 步把 MacBook 变成 7×24 远程主机,人在外面随时接管桌面
ios·agent·mac
weixin_403810131 天前
iOS免越狱自动化蓝牙HID方案:不装代理也能跑脚本
运维·ios·自动化·跨境电商·ai智能体·ios投屏·苹果投屏
GitLqr2 天前
Flutter 3.47 与 Dart 3.13:你必须了解的迁移指南
flutter·ios·dart
冯汉栩2 天前
Swift Control View,Label渐变颜色(源码)
开发语言·ios·swift
jike_20262 天前
iPhone日历查看会议纪要APP推荐:按日期查找历史录音更方便
ios·语音识别·iphone
冯汉栩2 天前
OC 技术 App上存蒲公英教程
ios