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<NSString *> * array) {

            for (NSString * str in array) {

                NSLog(@"加入过的WiFi:%@",str);

            }

        }];

相关推荐

  1. 修复 Ubuntu 2204 Wi-Fi 热点无法连接问题

    2024-06-05 20:54:09       42 阅读
  2. Wi-Fi信号EVM指标分析

    2024-06-05 20:54:09       18 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-05 20:54:09       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-05 20:54:09       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-05 20:54:09       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-05 20:54:09       18 阅读

热门阅读

  1. iOS内购欺诈漏洞

    2024-06-05 20:54:09       8 阅读
  2. #媒体#知识分享#职场发展

    2024-06-05 20:54:09       10 阅读
  3. 如何使用 Vue CLI 创建和管理一个 Vue 项目

    2024-06-05 20:54:09       8 阅读
  4. SD-WAN怎样提升企业办公效率

    2024-06-05 20:54:09       8 阅读
  5. 使用Node.js搭建服务器

    2024-06-05 20:54:09       7 阅读
  6. flask的一些简要基础问答

    2024-06-05 20:54:09       9 阅读
  7. React@16.x(16)Render Props

    2024-06-05 20:54:09       10 阅读
  8. React 中图片请求失败使用裂图

    2024-06-05 20:54:09       8 阅读
  9. React@16.x(15)PureComponent 和 memo

    2024-06-05 20:54:09       9 阅读
  10. react的hooks是什么意思

    2024-06-05 20:54:09       8 阅读
  11. 【Python】使用flask作为web服务器

    2024-06-05 20:54:09       9 阅读
  12. Python Flask是什么:深入解析与实用指南

    2024-06-05 20:54:09       10 阅读
  13. 前端面试题大合集7----模块化/工程化/ES6+标准

    2024-06-05 20:54:09       7 阅读
  14. 【ARM-Linux篇】根文件系统

    2024-06-05 20:54:09       9 阅读
  15. Android 11 AudioPolicyService 启动流程

    2024-06-05 20:54:09       7 阅读
  16. 示波器眼图怎么看

    2024-06-05 20:54:09       8 阅读