Can push notifications be used to run code without notifying the user?

I have an application that needs to communicate with the server (update its data) once every 24 hours. This should happen even if the application is not open and is not in the background.

Ideally, I would like to:

  • Every 24 hours my server sends a push notification to the iPad
  • This wakes up the application and runs the code needed to update the data.
  • The notification is then discarded.

Is it possible? Is the application only awakened AFTER the user clicks on the notification? Or can I run the code before showing the notification? Can I even refuse a notification?

If push notifications are not suitable for this, what is

Thanks guys!

+6
ios push-notification notifications background-process
source share
3 answers

With the release of iOS 7, this is finally possible with Remote / Silent notifications. They work the same way as push notifications, but instead of immediately warning the user, they can start background fetching and upload / download new content.

Here is a simple tutorial: http://www.objc.io/issue-5/multitasking.html

+9
source share

This is only possible if your application is an advertising application, if there is one, you can send a push notification using content-available: true once every 24 hours.

If this is not a newsstand app, you can use GPS fencing to run code instead. It is allowed to allow the user to configure GPS fences if they want the application to be updated when the user approaches an area (i.e. Home / work). This will wake the application, and you can start the background download. For example, Instapaper does this.

+2
source share

if the period is always 24 hours, you can use local notifications instead of push notifications.

your application will not be able to run any code if the user does not open the push notification, the push notifications will be processed by the OS, and your application will not control them until it is inactive or in the background you should take a look at the push notification programming guide

an alternative way to accomplish what you are trying to do is to get data from the server every time the application is launched, and the last update occurred 24 hours earlier,

  • every time you contact the server, save the date in NSUserDefault
  • every time the user opens the application, check if the last contact with the server occurred before 24 hours, and then update the data.
0
source share

All Articles