iOS11 App内自动连接Wi-Fi

栏目: IOS · 发布时间: 7年前

内容简介:背景:给智能设备配置网络,需要直连智能设备发射的Wi-Fi目前技术:iOS11后苹果提供  NEHotspotConfigurationManager 类直连周边Wi-Fi,iOS11前只能跳转到系统设置界面手动连接Wi-Fi步骤

背景:给智能设备配置网络,需要直连智能设备发射的Wi-Fi

目前技术:iOS11后苹果提供  NEHotspotConfigurationManager 类直连周边Wi-Fi,iOS11前只能跳转到系统设置界面手动连接Wi-Fi

步骤

1.给开发者中心给 Appid 配置连接Wi-Fi的权限

iOS11 App内自动连接Wi-Fi

2.Xcode - Build Phases - 引入NetworkExtension

iOS11 App内自动连接Wi-Fi

3.Xcode - Capabilities - Hostpot Configuration 勾选

iOS11 App内自动连接Wi-Fi

代码实现

引入 #import

if (@available(iOS 11.0, *)) {
        NEHotspotConfiguration * hotspotConfig = [[NEHotspotConfiguration alloc] initWithSSID:@"Deli_L1050ADNW_1B0000"];
        // 开始连接 (调用此方法后系统会自动弹窗确认)
        [[NEHotspotConfigurationManager sharedManager] applyConfiguration:hotspotConfig completionHandler:^(NSError * _Nullable error) {
            NSLog(@"%@",error);
            if (error && error.code != 13 && error.code != 7) {

            }else if(error.code ==7){//error code = 7 :用户点击了弹框取消按钮


            }else{// error code = 13 :已连接


            }

        }];
    } else {
          // iOS11以下版本逻辑
    }

以上说的方法不需要去苹果申请权限

注意事项

由于NEHotspotConfigurationManager.h在模拟器上不可用,导入方法为:

#if TARGET_IPHONE_SIMULATOR
#else
#import
#endif

代码逻辑同于注意事项1

作者:小岂几哥

链接:https://www.jianshu.com/p/376262eb9079


以上所述就是小编给大家介绍的《iOS11 App内自动连接Wi-Fi》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Introduction to Computation and Programming Using Python

Introduction to Computation and Programming Using Python

John V. Guttag / The MIT Press / 2013-7 / USD 25.00

This book introduces students with little or no prior programming experience to the art of computational problem solving using Python and various Python libraries, including PyLab. It provides student......一起来看看 《Introduction to Computation and Programming Using Python》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

随机密码生成器
随机密码生成器

多种字符组合密码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试