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

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

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

#import <NetworkExtension/NetworkExtension.h>

//无密码初始化

NEHotspotConfiguration *hotspotConfig = [[NEHotspotConfiguration alloc]initWithSSID:@"Wi-Fi名"];

//有密码初始化

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

\[NEHotspotConfigurationManager sharedManager\]applyConfiguration: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\ \* array) { **for** (NSString \* str **in** array) { NSLog(@"加入过的WiFi:%@",str); } }\];

相关推荐
开心就好20251 天前
使用Wireshark进行TCP数据包抓包分析:三次握手与四次挥手详解
后端·ios
开心就好20251 天前
Flutter iOS 包破解风险处理 可读信息抹除
后端·ios
报错小能手1 天前
ios开发方向——Swift语言学习 为啥要学Swift?
学习·ios·swift
哈__1 天前
ReactNative项目OpenHarmony三方库集成实战:react-native-push-notification-ios
react native·react.js·ios
2501_915909061 天前
iOS 抓包不越狱,代理抓包 和 数据线直连抓包两种实现方式
android·ios·小程序·https·uni-app·iphone·webview
Dante丶1 天前
Xcode 26.4 AFNetworking 私有头文件报错处理记录
ios
用户223586218201 天前
Xcode MCP Server 完全指南:从智能配置到编程控制
ios
游戏开发爱好者82 天前
入门 iOS 开发 新手工具开发首个应用
ide·vscode·ios·objective-c·个人开发·swift·敏捷流程
张飞签名上架2 天前
苹果签名机制全解析:守护生态安全的数字钥匙
ios·苹果签名·超级签·企业签名