

iOS11 App内自动连接Wi-Fi
source link: http://www.cocoachina.com/ios/20181018/25235.html?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

背景:给智能设备配置网络,需要直连智能设备发射的Wi-Fi
目前技术:iOS11后苹果提供 NEHotspotConfigurationManager 类直连周边Wi-Fi,iOS11前只能跳转到系统设置界面手动连接Wi-Fi
步骤
1.给开发者中心给 Appid 配置连接Wi-Fi的权限
2.Xcode - Build Phases - 引入NetworkExtension
3.Xcode - Capabilities - Hostpot Configuration 勾选
代码实现
引入 #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
Recommend
-
158
website upgrading…
-
232
website upgrading…
-
175
website upgrading…
-
213
website upgrading…
-
100
随着iOS11和xcode9刚开始正式发布,小编也迫不及待的更新了xcode9,手机也顺利更新到iOS,也终于见到iPhone X 的真面不,看着齐刘海的样式,小编心里淡淡的忧伤,怎么适配,如何快速适配到项目中,成了一个蛋疼的问题 文章讲解点: 1.首先看一下iPhone X的模拟器样...
-
125
iPhone - @longislet - 据她描述,手机在使用时突然弹出一个对话框,提示升级系统。对话框下方有两个选项分别是“立即”和“稍后”,她点了稍后,结果半夜更新被自动安装。现在手机处于软件动不动就闪退,即使不闪退也延迟严重,根本无法
-
128
Apple - @holysin - 明显感觉到操作超级卡,但是跑 geekbench 分数确实正常的,应该还是性能调整有问题,你们的 11.3 还顺畅么?
-
5
遇到的问题iOS 11 UINavigationItem.backBarItem 隐藏 “返回” 文字iOS 11之前是通过 UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffset(horizontal: CGFloat.greatestFiniteMagnitude , vertical...
-
6
iOS8、iOS9、iOS10、iOS11、iOS12、iOS13(20200210更新iOS13.3.1和12.4.5越狱)Jailbreak越狱工具集合_iOS_IT密码 本文收集iOS8、iOS9、iOS10、iOS11、iOS12、iOS13越狱工具集合,供参考。如有需要,请自行根据越狱工具名称搜索相关教程,注意32...
-
9
1.tableView向下偏移,部分UIScrollView布局出现混乱。 原因: 因iOS11弃用了automaticallyAdjustsScrollViewInsets 使用了contentInsetAdjustmentBehavior...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK