Packet tunnel provider sleep mechanism

We are developing a network extension that utilises the NEPacketTunnelProvider. We have noticed when the extension is running, and the phone screen is off, after about 10 seconds the device goes to system sleep (as evidenced by messages like “suspended timer for imminent system sleep” in the console logs) and the network extension simply won’t run any code during this time, therefore stopping traffic flow. When the device wakes up from sleep, such as when the screen comes on the network extension resumes executing code and runs normally.

The use case is relaying traffic from a device on the same Wi-Fi network to our server via the iPhone's cell socket. As such, we need it to work reliably when the screen is off and not freeze the network extension.

Is there any way to prevent the device from sleeping and freezing our extension when the screen is off? Also, if sleep causes the extension to pause code execution, then how would system services like APNS or includeAllNetworks (which forces all traffic through the tunnel) even work?

Would you give more details on how the wifi traffic from other devices reach the device and how the traffic hit the NEPacketTunnelProvider utun interface? When the device is in sleep, do you see the wifi traffic being received by the device?

We aren’t using the utun interface at the moment. We create sockets on the WiFi and cellular and then relay data from other devices received by the WiFi over the cellular to our server.

All traffic stops while the device is in sleep.

Packet tunnel provider sleep mechanism
 
 
Q