Is it possible to keep a socket connection alive in background, to be able to push new data and alert users at all times?
Background applications can eat up your battery and utilize the resources. There are some applications which probably won't be optimized well, some might be malicious or have malware, or some applications just have a bug.
To open Quick Settings, from the top of the screen, swipe down twice. To see the number of active apps running in the background: At the bottom left, tap # active apps. Or, at the bottom right, tap the number next to Settings and Power .
In Windows, apps can continue to perform actions even when you are not actively in the app's window. These are commonly called background apps. You can decide which apps will run in the background, and which won't.
The answer to this question is a definitive yes. If you are in the background state, then you can keep a connection open and process messages from a server.
Unfortunately the complexity here is that you don't have a lot of control over the state your application is in:
So obviously the trick here is how do I stay in the background state as a long as possible. There are a couple of ways to do this:
So these approaches are not without their own problems (getting approved on the store being one of them) and as such I tend to agree with the other answers that using push notifications is probably your best approach for notifying your users. With the notification improvements in iOS5 this is going to be the best user experience going forward.
You can keep a socket connection alive (or do whatever else you want) in the background for about 15 minutes after your app closes. There are also more specialized background processing modes (specifically, audio, voip, and location) which Apple supports if your app fits into one of their supported categories. See here.
If you want to keep sending the user notifications indefinitely, you want to use the Apple Push Notification Service. This allows your app to continue to receive notifications when it's not running, and it conserves resources since there's only one connection to the APN service at a time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With