Proper socket handling for iOS tablets
-
I have an iOS application written with Qt. The main application uses a QThread for socket communications with several connected signals to/from the main application thread. Realizing that under some circumstances the OS may take my connection away, such as when the table sleeps or my app is forced to the background, what is the best or proper way to:
- deal with the application state change with respect to my connection
- restore the connection when the application returns to the foreground
Do I need to disconnect my signals reflexively when the application state changes to SUSPENDED and then reconnect them when the state changes back to the foreground?
Can I just leave everything alone and check the connection state when I next try to send a message, and reconnect if connection is lost?
I appreciate any insight.
-
Hi,
Do you need to handle that use case or rather have your application run in background to continue its work ?
-
Hi,
Do you need to handle that use case or rather have your application run in background to continue its work ?
-
You should then connect the applicationStateChanged signal and store the state of your application when you get
Qt::ApplicationSuspended
. Depending on what your application is doing you might want to abort the current operation and restart it when the application resumes.If you can do it cleanly you shouldn't need to disconnect any signals.
-
You should then connect the applicationStateChanged signal and store the state of your application when you get
Qt::ApplicationSuspended
. Depending on what your application is doing you might want to abort the current operation and restart it when the application resumes.If you can do it cleanly you shouldn't need to disconnect any signals.
-
I'd be proactive. That way you always know the state you were in and that might avoid useless bandwidth usage.
-
I'd be proactive. That way you always know the state you were in and that might avoid useless bandwidth usage.