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

}

}];

相关推荐
壹方秘境1 天前
我用Go语言开发了一个跨平台的HTTPS抓包和调试工具
前端·后端·ios
初级代码游戏7 天前
easy Photo Clean公测版:快速清理iPhone照片 邀请公测
ios·iphone
库奇噜啦呼7 天前
【iOS】RunLoop学习
学习·ios
黑科技iOS上架7 天前
iOS应用周末提交什么情况算卡审
经验分享·ios
zzb15807 天前
ios基础-MVC-UIView
ios·mvc·cocoa
kingbal7 天前
Flutter:Flutter SDK版本管理工具FVM
android·flutter·ios·android-studio·window
他们都不看好你,偏偏你最不争气7 天前
【iOS】Runtime - Part 2 && 消息发送:缓存、查找与转发
macos·ios·objective-c·cocoa
2501_915918418 天前
iOS App性能测试工具的实现方法与优化循环指南
android·ios·小程序·https·uni-app·iphone·webview
他们都不看好你,偏偏你最不争气8 天前
【iOS】Runtime - Part 1 && 对象与类的本质
macos·ios·objective-c·cocoa