Hello,
I am using current xcode tool and running my app on device running ios 14.2
The APP is a UDP client and I am using CocoaAsyncSocket library, everything works fine on Foreground, but then when I put the phone to sleep and bring it back the UDP port seems error out and error indicates UDP port close.
After adding background fetch and then also tried background refresh: BGProcessingTask
2020-12-07 18:48:48.891998-0800 ParcelZoomAPP[1425:299402] Success submit request <BGProcessingTaskRequest: com.parcelzoom.refresh, earliestBeginDate: 2020-12-08 02:48:53 +0000, requiresExternalPower=0, requiresNetworkConnectivity=1>
From the debug info above, I gather the background task was getting created and scheduled correctly, and the UDP port behaves still the same.
digging further into the GCD/GCDAsyncUdpSocket.m I find the following:
Code seems to be pending on event:
dispatch
sourceset
eventhandler(receive4Source, ^{ @autoreleasepool {
and as soon as the device walksup and my APP is brought foreground, the control comes out of dispatch
sourceset
eventhandler and execute the next function call:
self->socket4FDBytesAvailable = dispatch
sourceget
data(self->receive4Source);
The dispatchsource
getdata return 0 in this case, the
CocoaAsyncSocket lib declares this as EOF and UDP port close. All the packet sent during this sleep duration - 1 or 2 tiny packet are all lost and never received due to this. Is the IOS kernel closing the UDP port when going into sleep or when waking-up? even having a Background task did not prevent the IOS kernel from reclaiming the UDP port. Is there some setting or APP capability would let the kernel know not destroy the UDP socket opened by client APP?
Thanks,