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

相关推荐
sunz_dragon9 分钟前
iPhone_签到App_自动化实战
ios·自动化·iphone
Digitally37 分钟前
如何轻松地使用隔空投送将iPhone内容传输到Android
android·ios·iphone
麦客奥德彪13 小时前
客户端 Trace Benchmark 体系设计
ios·数据分析
Digitally21 小时前
6 种简易方法轻松连接 iPad 与电脑
ios·电脑·ipad
2501_915921431 天前
uni-app一键生成iOS安装包并上传TestFlight全流程
android·ios·小程序·https·uni-app·iphone·webview
sp42a1 天前
如何在 NativeScript 中使用 iOS 的 Metal 着色器
ios·着色器·nativescript
Mr_CrazyPeter2 天前
iONSPlayer 1.1.1版本发布
游戏·ios·模拟器
秋雨梧桐叶落莳2 天前
iOS——UI入门
ui·ios·cocoa
zhensherlock2 天前
Protocol Launcher 系列:Agenda 优雅组织你的想法与日程
javascript·macos·ios·typescript·node.js·mac·ipad
Rhys..2 天前
webdriveragent setup教程
ios