What is the right way to check for data in remote database through http requests in objective c iOS. I am thinking of an nstimer that is called every 5 minutes. The nstimer will trigger a function with a thread in it. Is this the right way? Is this going to work when the app enters the background?
Any help appreciated.
The thread (as like all execution in your program) will pause when entering the background – and if it was waiting on a network response, that response will fail after the app returns to the foreground.
Moreover, you need to explicitly tell iOS when you are beginning a task that you would like to continue in the background (with
beginBackgroundTaskWithExpirationHandler:on yourUIApplicationsingleton) and when you have finished that task (withendBackgroundTask:). However, that is only up to a maximum of ten minutes, so I daresay you won’t be able to, say, continue your NSTimers in the background. But yes, the method you have described is fine for when the application is in the foreground.