tags:

views:

35

answers:

1

I would like to build an app which retrieves images from my server. My problem is that I want it to work in the background and only when there is a 'new image' to load.

It seems like what I need is very similar to PUSH notifications:

  • Work in the background
  • Only when there is 'something new' to load.

I guess what I want became possible with the new iOS4. Please tell me if this is feasible. Any links for how to even start thinking about it would be great. Thanks.

+1  A: 

It depends on what background you mean.

If you mean that your application is running and you have some thread to get the image in the background thread, it is possible.

If you mean that your application is suspended and you still want to use PUSH notification and get the image. I am afraid that it is impossible. When your application is in the background, it has very limited amount of time that it can run to finish its current task. When that time is out, your application cannot do anything.

You can receive some push notification and local notification like GPS, server notification when your application is suspended, but you can only receive the server notification and cannot download the new image. Here is the instruction from Apple Dev documentation:

When the operating system delivers a local or push notification and the target application is not running in the foreground, it presents the notification (alert, icon badge number, sound). If there is a notification alert and the user taps the action button (or moves the action slider), the application launches and calls the UIApplicationDelegate method application:didFinishLaunchingWithOptions:, passing in the local-notification object or remote-notification payload. If the application is running in the foreground when the notification is delivered, the application:didReceiveRemoteNotification: or application:didReceiveLocalNotification: method of the application delegate is invoked.

More here

vodkhang
so lets say the app received a GPS location, and by the same time I would like to make a request for a new image. is it possible?
shaimagz
Just edit my answer to add more details for you:)
vodkhang
Ok, Thanks. another quick question:you said: "If you mean that your application is running and you have some thread..." - does the application has to work on the foreground to do this?
shaimagz
yes, it has to.
vodkhang