我的应用程序使用NEHotspotConfigurationManager
连接到特定设备的Wi-Fi,该设备充当WPA2访问点。在旧版iOS(iOS 12及更低版本)中,一切正常,但在iPadOS / iOS 13中,每次都会在一段时间后断开连接。如何保持连接而不永久存储NEHotspotConfiguration
?
我怀疑这与一个新功能有关-多窗口(我的应用程序不支持)。原因是在我的NEHotspotConfiguration
中,我将joinOnce
标志设置为true
(因为该设备的网络永远不应在应用程序外使用)。 Apple的文档说明:
当
joinOnce
设置为true时,热点仅在配置它的应用程序在前台运行时保持配置和连接。当发生以下任何事件时,热点将断开连接并删除其配置:
- 应用程序在后台超过15秒。
- 设备休眠。
- 应用程序崩溃、退出或卸载。
- 应用程序将设备连接到不同的Wi-Fi网络。
也许我的应用程序被错误地识别为离开前台。
将joinOnce
设置为false
可以使应用程序保持连接,但这不是可接受的解决方案,因为我的设备不提供Internet连接,并且不能在应用程序外使用。
以下是我如何应用热点配置:
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
时,我希望连接保持打开状态。