iOS11 App内自动连接Wi-Fi

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

内容简介:背景:给智能设备配置网络,需要直连智能设备发射的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》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

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

The Definitive Guide to HTML5 WebSocket

The Definitive Guide to HTML5 WebSocket

Vanessa Wang、Frank Salim、Peter Moskovits / Apress / 2013-3 / USD 26.30

The browser is, hands down, the most popular and ubiquitous deployment platform available to us today: virtually every computer, smartphone, tablet, and just about every other form factor imaginable c......一起来看看 《The Definitive Guide to HTML5 WebSocket》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具