问题
acani uses zimt websocket for chat. Can we make it so that when a user closes his phone and puts it in his pocket, he can still receive chat messages from and send location updates to the node.js server? I think this would be nicer than push notifications. Don't you? If not, why should we use push notifications instead or also?
Thanks!
回答1:
You can't keep a network socket open, unless you are registered for voip/GPS/music playing in the background.
if you register for these, and then don't do them, apple usually reject the app.
the reason you cant keep a network socket open, is that without your app jumping to the foreground when it receives a connection, it cannot respond to network traffic(because if it is not in the foreground its memory content is frozen).
background network traffic kills the battery, as the radios in phones are one of the most energy intensive parts.
with push notifications, apple manage how often they are sent out, so you don't have all of the applications on the phone polling the network every 2 minutes killing the battery, you only have one active network connection, which is intermittent.
来源:https://stackoverflow.com/questions/4456407/iphone-keep-websocket-open-in-background