iPadOS:通过NEHotspotConfiguration连接的网络在一段时间后断开连接 [英] iPadOS: Network connected via NEHotspotConfiguration disconnects after a while

查看:303
本文介绍了iPadOS:通过NEHotspotConfiguration连接的网络在一段时间后断开连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用使用NEHotspotConfigurationManager通过Wi-Fi将自身连接到特定设备.该设备充当WPA2接入点.在较旧的iOS版本(iOS 12及更低版本)中,一切正常,但在iPadOS/iOS 13中,每隔一段时间就会断开设备的连接.如何保持连接而不永久存储NEHotspotConfiguration?

My app uses NEHotspotConfigurationManager to connect itself to a certain device using a Wi-Fi. The device acts as an WPA2 access point. In older iOS versions (iOS 12 and lower) everything worked fine, but in iPadOS/iOS 13 the device is being disconnected after a while every single time. How to keep a connection on without storing NEHotspotConfiguration permanently?

我怀疑它与新功能-多个Windows(我的应用程序不支持)有关.原因是在我的NEHotspotConfiguration中,我将joinOnce标志设置为true(因为从不应该在应用程序外部使用设备的网络). Apple的文档指出:

I suspect that it has something to do with a new feature - Multiple Windows (which is not supported by my app). The reason is that in my NEHotspotConfiguration I set joinOnce flag to true (since the device's network should never be used outside the app). Apple's documentation states:

当joinOnce设置为true时,仅在配置了热点的应用程序在前台运行时,热点才会保持配置和连接.发生以下任何事件时,都会断开热点并删除其配置:

When joinOnce is set to true, the hotspot remains configured and connected only as long as the app that configured it is running in the foreground. The hotspot is disconnected and its configuration is removed when any of the following events occurs:

  • 该应用程序在后台停留超过15秒.
  • 设备进入睡眠状态.
  • 该应用程序崩溃,退出或已卸载.
  • 该应用将设备连接到其他Wi-Fi网络.

也许我的应用被错误地识别为前景.

Perhaps my app is falsely recognized as leaving a foreground.

joinOnce设置为false可使应用程序保持连接状态,但这不是可接受的解决方案,因为我的设备不提供Internet连接,因此不能在应用程序外部使用.

Setting joinOnce to false makes the app keep the connection on, but it's not an acceptable solution, since my device doesn't provide an Internet connection and it must not be used outside the app.

这是我应用热点配置的方法:

Here is how I apply the hotspot configuration:

let hotspotConfiguration = NEHotspotConfiguration(ssid: self.ssid, passphrase: self.passphrase, isWEP: false)
hotspotConfiguration.joinOnce = true
       
NEHotspotConfigurationManager.shared.apply(hotspotConfiguration) { error in
    // connection is successfully applied
    // and about 15 seconds later it is lost.
}

我希望在joinOnce标志设置为true时保持连接状态.

I expect the connection to be kept on when joinOnce flag is set to true.

推荐答案

Apple似乎已解决了iOS 13.4 beta 2中的问题,如所示,它现在可以与joinOnce = true一起使用. 在苹果论坛上的相关讨论

Apple appears to have fixed the issue in iOS 13.4 beta 2, it now works with joinOnce = true as documented. Related discussion on Apple's forum

这篇关于iPadOS:通过NEHotspotConfiguration连接的网络在一段时间后断开连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆