4
  • In our app, we notify users using Push-notifications, but if user didn't received push (e.g. user's device is offline), then we send him SMS.
  • Since APNs doesn't provide delivery report, we have implemented our own method of sending reports to backend server using Service Extension:

    • When app receives push notification, it sends an http-request to backend inside Service Extension's method -

      didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void)

It is possible to make a fetch job or make http requests only within 30 seconds.

However, sometimes users complain about receiving SMS and PUSH at the same time.

When we inspect logs in DB, there are no PUSH delivery reports from those devices.

My questions are:

  1. Is there any chance that Service Extension fails to start?
  2. Any advices on how to troubleshoot such errors?
Yerlan Ismailov
  • 109
  • 1
  • 7

2 Answers2

0

In Your app you might have enabled Background Mode or Remote notifications in your app's target Capabilities along with Service Extension. So what is happening is, when you receive push notification your app is active for around 30 secs. In this time your delivery service gets called and updates your server. Since the notifications doesn't contains any media, it takes sometime to show the notification.

But as soon as you get the delivery your server sends a SMS to the user. So this is the reason why you are getting APN and SMS at the same time.

Fix: Add a delay at your server for sending SMS by around 1 min. So as to avoid conflict.

manishsharma93
  • 1,039
  • 1
  • 11
  • 26
0

The idea of phoning home inside a Service Extension is flawed because if for some reason the HTTP call fails inside the extension (e.g. bad cell reception, server hiccup, ...) you have no way of preventing the notification to be delivered:

The service extension [..] doesn't have the power to drop this notification or prevent it from being displayed.

As mentioned in this WWDC 17 talk: Best Practices and What’s New in User Notifications

A better way would be to send a silent notification to the user. This will wake up your app in the background on the user's device allowing you to make the HTTP call. If the call succeeds you can schedule a local notification. If it fails (or if the silent notification was never delivered) the user is offline and you can send an SMS instead.

Keep in mind: Apple treats silent notifications as low-priority, so to prevent a local notification being scheduled by a silent notification that was delivered after the SMS has been sent, you should implement some sort of API call your app can use to query whether or not an SMS has already been sent.

Kymer
  • 1,184
  • 8
  • 20