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

相关推荐
搜狐技术产品小编20231 小时前
CAEmitterLayer:iOS 中创建炫酷粒子效果的魔法工具
macos·ios·objective-c·cocoa
00后程序员张19 小时前
iOS App 混淆与资源保护:iOS配置文件加密、ipa文件安全、代码与多媒体资源防护全流程指南
android·安全·ios·小程序·uni-app·cocoa·iphone
咕噜签名分发冰淇淋21 小时前
内测分发是什么?
ios
2501_916007471 天前
Transporter App 使用全流程详解:iOS 应用 ipa 上传工具、 uni-app 应用发布指南
android·ios·小程序·https·uni-app·iphone·webview
白玉cfc1 天前
【OC】单例模式
开发语言·ios·单例模式·objective-c
Digitally1 天前
比较 iPhone:全面比较 iPhone 17 系列
android·ios·iphone
2501_915909061 天前
HTTPS 错误解析,常见 HTTPS 抓包失败、443 端口错误与 iOS 抓包调试全攻略
android·网络协议·ios·小程序·https·uni-app·iphone
他们都不看好你,偏偏你最不争气2 天前
【iOS】UIViewController
开发语言·macos·ios·objective-c·cocoa
前端小超超2 天前
如何配置capacitor 打包的ios app固定竖屏展示?
前端·ios·web app
CocoaKier2 天前
AI让35岁程序员再次伟大
ios·微信小程序·aigc