Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have an app which needs to communicate with a server (to refresh it's data) once every 24 hours. This needs to happen even if the app is not open, nor in the background.

Ideally what I'd like is:

  • Every 24 hours, my server sends a push notification to iPad
  • This wakes up the app, and runs the code necessary to refresh the data
  • The notification is then discarded

Is any of this possible?
Is the app only woken up AFTER the user clicks on the notification? Or can I run some code before showing the notification? Can I even discard the notification message?

If Push notifications are not the right way to do this, what is???

Thanks guys!

like image 963
theDuncs Avatar asked Aug 08 '12 09:08

theDuncs


2 Answers

With release of iOS 7 this is finally possible using Remote/Silent notifications. They work same as Push notifications but instead of alerting the user immediately they can fire up background fetch mode and upload/download new content.

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

like image 117
Borbea Avatar answered Oct 20 '22 01:10

Borbea


This is only possible if your application is a Newsstand App, if it is, you can send a push notification with content-available: true once every 24 hours.

If it is not a newsstand app, you can instead use GPS fences to run code. It is allowed to let the user set up GPS fences if they want the app to update when the user comes close to an area (ie. their home / work). This will wake the app and you can run the background download then. Instapaper for example does this.

like image 36
Hampus Nilsson Avatar answered Oct 19 '22 23:10

Hampus Nilsson