I've been trying to implement the following scenario:
When an event is cancelled, send a push notification to all devices that were subscribed to that event in order to remove the already queued local notification for the event's starting time.
Think of it as a calendar. If an event gets cancelled, no local notification should be displayed on the devices when the event's starting time comes.
I've been trying to send a silent(background) push notification to the iOS devices which will do two things:
- display the notification banner (saying something like The event "X" was cancelled)
- wake up the terminated app to run some code (remove the queued local alert that was supposed to fire on the event's starting time)
but I could not make it work when the application is terminated.
I've checked the "Remote notifications" option in the Background Modes of the app's Capabilities, implemented the application:didReceiveRemoteNotification:fetchCompletionHandler
method in AppDelegate
and I've sent the following payload:
{
aps: {
alert: @message,
sound: 'default',
badge: 1,
'content-available' => 1
},
objectId: 1,
type: 'removed'
}
I've also included the header fields:
apns-push-type = BACKGROUND
apns-priority = 5
The application:didReceiveRemoteNotification:fetchCompletionHandler
is called only when the app is in FOREGROUND or BACKGROUND, but not when it is INACTIVE (killed, closed, terminated via app switcher...)
Is it possible to achieve the behaviour that I want? Note: I'm using ios 13.5.1