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

}

}];

相关推荐
CHB2 天前
uni-app x 蒸汽模式 性能测试基准报告 Benchmark【Android版】
android·ios·uni-app
Magic-ZYJ2 天前
不登录、不联网也能用:我是如何设计一款“本地优先”iOS App 的
ios·app·iphone·研发·独立开发者·心情日记
_阿南_2 天前
flutter 展示的字体突然奔放了
android·flutter·ios
90后的晨仔2 天前
你的 iOS 最低部署版本即将不再被 App Store 接受
ios
2601_965798472 天前
Launch Your Wellness App Fast: The Truth About Meditation Source Code
前端·macos·ios·objective-c·cocoa
初级代码游戏3 天前
iOS开发 Swift 速记7:结构体和类
开发语言·ios·swift
Anhty3 天前
手机端叮咚变声器2026实测:功能表现、优缺点完整解析
功能测试·ios·智能手机·安卓
SameX3 天前
后台定位耗电的问题,我花两年把它压到了3%-5%
ios
星辰即远方3 天前
计算器仿写总结
学习·ui·ios·cocoa·xcode
游戏开发爱好者84 天前
系统状态:专为iPhone和iPad设计的实时系统性能监控工具全面介绍
android·ios·小程序·uni-app·iphone·webview·ipad