18
votes

My app performs silent background fetch via push notifications. Everything is working fine, and push notifications sent from our server trigger silent background fetches as expected, when the user has opened the app within the last 60 minutes or a push notification has been sent within 60 minutes - even if the device is locked.

However, when the user doesn't open the app for 2-3 hours or when a push notification hasn't been sent in 2-3 hours, the app isn't receiving the push notification. I have been logging app activity, and I've confirmed that:

didReceiveRemoteNotification:fetchCompletionHandler:

is not being called on the app delegate.

A few more facts:

  1. In the app's plist.info, I have set UIRequiresPersistentWiFi to true and UIBackgroundModes to (only) remote-notification
  2. The push notification payload contains only the content-available key
  3. After 2-3 hours of inactivity (either from no push notification sent or no user activity), I am seeing the same result on both my iPhone 5 and Wifi-only iPad 2, both running iOS 8.1.2. In other words, it doesn't matter whether the internet connection is cellular or Wifi.
  4. I don't believe I am hitting rate-limit boundaries, as I am only sending at most 1-2 push notifications per device per hour.

My understanding is that iOS should continue to wake the app up in the background and enable it to process the background fetch from the push notification - even after hours of inactivity (as long as the device is awake and has an internet connection).

I'm wondering if anyone else has experienced this, and if so, if you've found a workaround.

Thanks in advance!

4
We have a similar problem. If I send "content-available":1 notification after a longer period of inactivity, it is ignored. However if I send a "regular" notification it appears on the phone. I can't really find a pattern, since for example I left 2 phones overnight, and one of them responded, and the other didn't. Did you manage to find any further leads to the problem?Nemanja Maksimovic
Did you every find a solution for this? I am having the same issue...Jacob
@Jacob, did you tried to send a payload with empty "sound" key? this usually worksSega-Zero
@Sega-Zero I sent "" for the sound key, yes.Jacob
try to sent a payload with 0 badge (or the number that was set previously) and then content-avaliable. Hope that will force payload to be sent to an app.Sega-Zero

4 Answers

1
votes

go through

Targets > Capabilities > Background Modes

Turn on Background Modes

0
votes

There is no work-around as such. You can try PushKit (iOS VOIP push notifications), which are more reliable but iOS8 only or VOIP persistent socket, which is available from iOS7 (much more difficult).

Apple does not guarantee immediate delivery for background / fetch push notifications (containing: content-available=1). Those notifications were designed to give app a chance to update its content in between runs, not to be 'immediate' nor reliable.

iOS will decide when to deliver this notifications based on undocumented, energy related conditions.

In other words - your app will be notified, only when iOS decides, it does not affect the battery. From my observations, it depends on many things, like:

  • if your device is connected to power source,
  • uses Wi-Fi of 3G,
  • time from last notification,
  • energy and data bandwidth app used when processing last one, itd...
  • when and how was device used in recent past (locked / unlocked screen)

I even noticed the difference between app running in debug session (by Xcode, connected by cable) - notifications were always delivered, and when I started app from Springboard / in release mode (different energy conditions) - then it started misbehaving.

0
votes
 [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]];
 [[UIApplication sharedApplication] registerForRemoteNotifications];
0
votes

Try this in your info.plist it worked for me.

info plist file.

This will awake your app to receive notification in background mode.