2

I have created a web-service app and i want to populate my view controllers according to the response i fetch(via GET) in main thread. But i want to create a scheduled timer which will go and control my server, if there becomes any difference(let's say if the count of an array has changed) i will create a local notification. As far as i read from here and some google results, i cant run my app in background more then ten minutes expect from some special situations(Audio, Vo-IP, GPS).. But i need to control the server at least one per minute.. Can anyone offer some idea-or link please?

EDIT
I will not sell the app in store, just for a local area network. Let's say, from the server i will send some text messages to the users and if a new message comes, the count of messages array will increment, in this situation i will create a notification. I need to keep this 'controlling' routing alive forever, whether in foreground or background. Does GCD give such a solution do anyone have any idea?

ilhnctn
  • 2,210
  • 3
  • 23
  • 41

2 Answers2

0

Note: "[...] I fetch (via GET) in main thread." This is not a good approach. You should never fetch any network resources on the main thread. Why? Because your GUI, which is maintained by the main thread, will become unresponsive whenever a fetch isn't instantaneous. Any lag spike on the network results in a less than desirable user experience.

Answer: Aside from the listed special situations, you can't run background apps. The way I see it:

  • Don't put the app in the background. (crappy solution)
  • Try putting another "entity" between the app and the "server". I don't know why you "need to control the server at least one per minute" but perhaps you can delegate this "control" to another process outside the device?

.

iOS app  ->  some form of proxy server -> server which requires
                                          "babysitting" every minute.
  • I will not sell the app in store, just for a local area network. Let's say, from the server i will send some text messages to the users and if a new message comes, the count of messages array will increment, in this situation i will create a notification. I need to keep this 'controlling' routing alive forever, whether in foreground or background. Does GCD give such a solution do you have any idea? – ilhnctn Mar 16 '12 at 15:42
0

Just simply play a mute audio file in loop in the background, OR, ping the user's location in the background. Yes, that will drain the battery a bit, but it's a simple hack for in-home applications. Just remember to enable the background types in your Info.plist!

Richard J. Ross III
  • 55,009
  • 24
  • 135
  • 201
  • If you have some sample code-or tutorial can you share please? If not i will try anyway:) – ilhnctn Mar 16 '12 at 15:54
  • thanks, i'm not so experienced with programming so i asked for tutorials:) but i think i will grab it easy – ilhnctn Mar 16 '12 at 16:36