The online home of John Pollard

More Reliable Background Notifications

I’m really happy with the “Show the days left as a counter on the app’s badge” feature on Count The Days Left, but unfortunately due to the way Apple implements background fetches makes it a little unreliable in staying up to date.

The latest version of the app fixes this by using push notifications to regularly wake the app to update itself.

Background fetch is unreliable

The problem was that I was using the background fetch feature to run the app in the background every so often, and when it runs update the number of days left on the badge.

However, the frequency the background fetches are run is completely down to the operating system. Now as far as I understand, iOS will allocate background processing time based on how often the app is used.

Obviously this causes a bit of a logical error. If the user enables the badge to show the number of days left, they are a lot less likely to open the app - which obviously means it’s less likely to run in the background, so is more likely to be wrong :(

Push notifications solve the problem

The best way of fixing this issue is to send out regular push notifications to the app, so it’s guaranteed to wake up and refresh the badge count.

In an earlier post I wrote about how I’ve found Azure the easiest way to set up the server side of things, and I did the same here.

I then send out notification with "content_available": 1 in the payload, which will not show anything in the Notification Center to the user, but the app will wake up in the background and run the code to update the app.

Obviously this means setting up some (minimal) server infrastructure to manage this. I’ve written a NodeJS script that triggers the push notification via the Azure API, and setup a cron job to run the script every 6 hours.

So far for me this has worked a treat, and I’m much happier with the solution even though it took a bit more work.

The new version of the app (v2.0.4) is available on the App Store right now.