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); } }\];

相关推荐
徐赛俊2 小时前
IOS快捷指令:一键静音 / 恢复
ios
2501_915918416 小时前
常见 iOS 抓包工具的使用,从代理抓包、设备抓包到数据流抓包
android·ios·小程序·https·uni-app·iphone·webview
handsome09167 小时前
uniapp打包的app,报This app was built with the iOS 18.1 SDK解决方案
ios·uni-app
初级代码游戏11 小时前
iOS开发 SwiftUI 15:手势 拖动 缩放 旋转
ios·swiftui·swift
森之鸟14 小时前
iOS云打包之Shorebird
ios
GuokLiu14 小时前
260203-OpenWebUI-在Windows上和RHEL上部署Caddy的步骤+在iPhone上操作的步骤
windows·ios·iphone
2501_915921431 天前
傻瓜式 HTTPS 抓包,简单抓取iOS设备数据
android·网络协议·ios·小程序·https·uni-app·iphone
恋猫de小郭1 天前
Flutter 在 Android 出现随机字体裁剪?其实是图层合并时的边界计算问题
android·flutter·ios
2501_915918411 天前
把 iOS 性能监控融入日常开发与测试流程的做法
android·ios·小程序·https·uni-app·iphone·webview
Digitally1 天前
如何轻松地将大型音频文件从 iPhone 发送到不同的设备
ios·iphone