Why does CocoaAsyncSocket in iOS 14 stops working until you rebuild via Xcode?

I have created a SwiftUI app in Xcode 12.0.1 building under iOS 14.
My app reads UDP data sent over a local network and for that I use the CocoaAsyncSocket library.
This is an example of Server class:

Code Block
class UDPServer : NSObject, GCDAsyncUdpSocketDelegate {
var PORT : UInt16;
var socket:GCDAsyncUdpSocket!;
init(port: UInt16){
self.PORT = UInt16(UserDefaultsHelper.getPort())
super.init()
socket = GCDAsyncUdpSocket(delegate: self, delegateQueue:DispatchQueue.main)
socket.setIPv4Enabled(true)
socket.setIPv6Enabled(true)
}
func start() {
do {
try socket.bind(toPort: PORT)
print("Socket bound to port \(PORT)")
try socket.beginReceiving()
} catch {
print(error)
socket.close()
}
}
func stop() {
socket.close();
}
func udpSocket(_ sock: GCDAsyncUdpSocket, didReceive data: Data, fromAddress address: Data, withFilterContext filterContext: Any?) {
//do stuff with the data
}


When I test the app on a physical device, UDP packets are received and the app works fine. I can close the app, disconnect the socket (calling close()), connect again (calling start()) and continue to receive packets.

If I don't use the app for around 12 hours and then open it again and try to connect, the socket binds to the port but the app doesn't receive any data. Even if I close/terminate the app and reopen it, or if I restart the device, and then reopen the app, no data is received. This happens on both iPad and iPhone devices, but not in the simulator.

However, if I rebuild the app via XCode and run it on my device (Product -> Run, while the device is connected) it starts to work again.

Some users have said that they never receive packets, even though they are being sent over the network.

I have been experiencing this on many devices, and many test flight users are experiencing this too. This did not happen when the product was built for iOS 13.
What is causing the app to fail to receive packets? And why does rebuilding and running the app via XCode seem to temporarily solve this problem?

I noticed that there was a similar issue reported here: https://developer.apple.com/forums/thread/662082?login=true

I attempted to request the multicast entitlement from apple, but they said that it was not required as I was only receiving unicast data.

Why does CocoaAsyncSocket in iOS 14 stops working until you rebuild via Xcode?
 
 
Q