0

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:

  1. display the notification banner (saying something like The event "X" was cancelled)
  2. 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

Bogdan Razvan
  • 1,497
  • 1
  • 16
  • 16
  • Does this answer your question? [IOS notification when Application is closed](https://stackoverflow.com/questions/45057772/ios-notification-when-application-is-closed) – Quentin Hayot Jul 07 '20 at 15:04
  • TL;DR from the duplicate: It's normal behavior. iOS will not run any code from your app if it was closed by the user. Same goes for geofences. – Quentin Hayot Jul 07 '20 at 15:05
  • @QuentinHayot what is says is that didReceiveRemoteNotification method will not get called when the application is closed, but would there be any other way to achieve this behaviour? – Bogdan Razvan Jul 07 '20 at 15:27
  • @LalKrishna do you mean PushKit's voip notifications? If so, aren't they a reason to get your app rejected from the store if used this way? – Bogdan Razvan Jul 07 '20 at 15:29
  • Sorry. We can't use PushKit if the app doesn't support VoiP calls. https://stackoverflow.com/a/58162829/4061501 – Lal Krishna Jul 07 '20 at 15:40
  • When a device receives a background notification, the system may hold and delay the delivery of the notification, which may cause Notification discard by the system if something force quits or kills the app. [Read more](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_background_updates_to_your_app) – Lal Krishna Jul 07 '20 at 15:41

0 Answers0