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);

}

}];

相关推荐
catchadmin11 小时前
NativePHP v4 让 Blade 构建原生 iOS 与 Android 界面
android·ios·ai·php
weixin_4038101313 小时前
iOS免越狱自动化三种方式对比:代理模式、蓝牙HID与OTG HID怎么选
ios·自动化·跨境电商·ios脚本·苹果群控·苹果投屏·苹果脚本
_瑞17 小时前
APM_函数调用栈展开
ios·编译原理
极客猴子21 小时前
会议记录带日历功能的iOS录音软件推荐:按日期查找会议内容
ios
2501_915918411 天前
Rust 程序抓包解密,rustls 不认系统证书的几种办法
开发语言·后端·网络协议·ios·adb·https·rust
MaoJiu1 天前
「Landmark-Driven Beauty Rendering:实时磨皮与腮红的算法与 GPU 实现」
ios
冯汉栩2 天前
Swift Control RollingCountdownView(动画倒计时)
开发语言·ios·swift
_瑞2 天前
读懂 iOS 的线程调用栈
ios·编译原理·汇编语言
末代iOS程序员华仔2 天前
iOS 语聊直播/聊天APP4.3条例被拒解决
flutter·ios·swift
2601_965798473 天前
Build a Fast, High-Ranking Restaurant Website with Rolanda Theme
开发语言·ios·swift