An iPhone app, connecting to a remote server via TCP. The use scenarios are:
- app (user) sends data to server and server responds data back.
- server might send data to app while it does nothing.
Assume that if app does not send data to server for 30 minutes, server will close the connection. I want to keep the connection alive for 120 minutes even if user does nothing.
Case 1: if app is in foreground, I can use timer to send some do-nothing data to server. No problem.
Case 2: if user pressed Home and app went to background, what could I do? I don't wan to show alert or something to interrupt user(he is away or playing games). I just wanna keep the connection alive for a longer period and when user comes back to the app, he found out that the connection will be still alive and be happy with that.
I have read documentations about background execution, multitasking, and local notifications of iphone APIs. I'm not sure whether if I can achieve Case 2.
Only use legal APIs, no jailbreaking.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…