Push Notifications · Silent Notification | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/1258151-push-notifications/lessons/6

Are silent notifications sent only when user has the app open?
Eg. if app is closed/minimised, and I send a silent notification, will the otter data be added to the table? Because in my case, it is not being added. However, it is added if I have that screen/tally screen open/app open.

https://stackoverflow.com/questions/41449134/can-i-handle-a-silent-notification-when-app-is-terminated-in-objective-c - Here Pushkraj thinks app should handle silent notification when minimised, but isn’t happening in my case… with the Ending example as downloaded from silent notification example…

it should work when the app is closed/minimised. You’ve done the 3 things?

  • “content-available”: 1
  • Background Modes capability
  • didReceiveRemoteNotification in AppDelegate

Yeah, I have.
When the application is not minimised, a row gets added to the tableview. However, when minimised, doesn’t get added. Can you confirm with the latest version of Xcode? The ending sample code provided is what I used, and again I can confirm that a row gets added to the tableview based on notification I send when app is not minimised, but when minimised, row isn’t added.
I asked for you to check with latest version of Xcode because the interface has changed a bit and under background modes, we also have an option for Background Processing (which I also checked, but still didn’t work.)

My apologies, I take back my question. It does work, wasn’t working previously but surprisingly, works now. Will test and let you know, if I come to know what I did wrong previously.

Hi Audrey,

I’ve done all of these steps, however the app is not receiving the silent notification if the app is not open. Has there been any updates to this that I’m missing?

Thanks,
Nick

hi Nick! Yes, it seems Apple has added requirements for HTTP headers.

Also, Catalina now refuses to open the PushNotifications app from onmyway, so you might need to use the sendEncrypted.php file from Part 2 of this course.

The relevant headers are:

'apns-push-type: ' . 'background'
'apns-priority: ' . '5' 

I’m not sure whether 5 should be in quotes or not.

Yep that worked, thanks! Posting the payload in case it helps someone else.

{
  "aps": {
    "content-available": 1
  },
  "image": "https://bit.ly/2GXRYox",
  "text": "Otterly cute!",
  "apns-push-type": "background",
  "apns-priority": "5"
}

thanks Nick! It’s interesting that these worked as part of the payload. @gargoyle indicated in his book update that they’d have to be HTTP headers.

Ah yeah I think I misunderstood. When I originally asked the question, for some reason, I wasn’t getting the silent notifications when the app was backgrounded. I made this change to the payload and it started working. Now it’s also working without those additional keys in the payload when the app is backgrounded. However it’s not working if the app is in a Non-running state. Are those keys needed in the header in order to receive the notifications if the app is in a “Non-running” state?

From Apple’s documentation:

Specify 5 to send the notification based on power considerations on the user’s device. Use this priority for notifications that have a payload that includes the content-available key. Notifications with this priority might be grouped and delivered in bursts to the user’s device. They may also be throttled, and in some cases not delivered.

Those are HTTP headers. You can put then in the body but APNs will just ignore them and assume they’re part of your personal content.