Vijay
Vijay

Reputation: 1016

iPhone background network connection by timer

Hi I want to call webservice from background at every 5 minutes and according to the response i want to show notification to the user . Is there a way to do this on iOS 4 ? I think it is possible by using CLLocation manager. Please Suggest Me How to do this.

Thanks !

Upvotes: 0

Views: 429

Answers (2)

user814037
user814037

Reputation:

Using a background mode for anything other than what it was designed for is a sure fire way to get your app rejected.

Since you want to access a web service periodically, why not do it from a server.

  1. When you app first launches register the device for Remote Notifications
  2. When your app gets notified it's about to go to the background, ping your web server with the device token returned from step 1
  3. Have your web server call the external web service every five minutes
  4. When you receive an appropriate response, send a Remote Notification to the device using the device token
  5. When the user acknowledges the notification and opens your app, have the app download what ever information it needs from your server or the external web service

If you provide a little more information with regards the context of your app this solution could be refined further.

Upvotes: 1

rckoenes
rckoenes

Reputation: 69489

No and yes, when you apps get pushed to the background all NSTimers are invalidate and your app sort of goes in a suspended mode.

There are only three types of apps that can run in background (audio, voip and locationbased). When using CLLocationManager you app will only receive major change. thus there is no way to it to do that every 5 min.

Upvotes: 1

Related Questions