This happens on device and not on simulator. I opened my app and connected to server using GCDAsyncSocket. When I press home button, putting the app in background, and then switch back to the app, the socket still connects. No problem here.
But if I actually lock the device then unlock it, even right away, the socket disconnects. The error from - (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err {
delegate method says...
err: Error Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo=0x20051cb0 {NSLocalizedDescription=Socket closed by remote peer}
I've checked with server and there's no code that explicitly destroy a connection. I think it's iOS related thing that kills the connection when app is sent to background. But then, I wonder if it's because the app was sent to background, then why home button doesn't kill the connection but locking the device does?
Is there any way to fix this?
===== Current Progress =====
Seems like there will be no solution for this. For now as a work around. I just reconnect if it disconnects unexpectedly. Will keep this question unanswered in hope for a miracle. ;)