Background Notification Issues

When using silent push notifications to create a core data entry such as detailed in chapter 8 , I can make this consistently fail in testing. Initially the task works correctly in all three states [Foreground, background, not running], however if close the app, use another app such as Safari or Mail then send the notification it will fail to write to core data. I have had this issue across multiple different approaches to implement the functionality, even using service extension and handling the write there has the same issue. Any ideas on the issue or a solution?

Using Swift UI

{
“headers”: {
“apns-push-type” : “background”,
“apns-priority” : “5”
},
“aps”: {
“content-available”: 1
},
“title”: “test”,
“text”: “A test notification”
}

The apns-topic, apns-push-type and apns-priority have to be HTTP headers, not a “headers” key in the payload that you’re sending.

Thanks for your reply, indeed sorry I did include headers in the body for the example provided (I’m using FCM in the base project so forgot to remove) however, I have tested the same with the correct body and using other testing tools that include HTTP header options to be set correctly, every time I get the same still get the same behaviour mentioned. Does sandbox V’s production have any effect on this? It is the only difference I can find. Presumably you can not replicate the same bug in the project example? Background notifications are delivered after closing the app, it only starts to fail after another app has been used, then background notifications are not processed further until the app has been launched again.

→ Request
POST https://api.sandbox.push.apple.com:443/3/device/xxxxxx
HEADERS
apns-topic: xxxxx
apns-priority:5
apns-push-type:background
Authorization:bearer xxxxx
MESSAGE
{
“aps” : {
“content-available” : 1
},
“title” : “test 2204”,
“text” : “A test notification”
}


Response

status code 200

Headers

apns-id xxxxx