iPadOS: Network connected via NEHotspotConfiguration disconnects after a while

你离开我真会死。 提交于 2019-12-03 08:50:11

问题


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?

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:

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:

  • The app stays in the background for more than 15 seconds.
  • The device sleeps.
  • The app crashes, quits, or is uninstalled.
  • The app connects the device to a different Wi-Fi network.

Perhaps my app is falsely recognized as leaving a foreground.

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.
}

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

来源:https://stackoverflow.com/questions/57552952/ipados-network-connected-via-nehotspotconfiguration-disconnects-after-a-while

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!