How to detect uninstall using FCM on IOS?

Viewed 473

TL;DR

I'm detecting uninstalls using FCM. If I receive a NotRegistered token on sending notification, I assume that the app has been uninstalled.

Everything works fine with Android, while on IOS I'm always getting a success response, even if the app has uninstalled for days.

More info

I have read that it is possible to detect uninstalls using APNs feedback Service, where Apple reports any inactive tokens.

Also I read on Firebase official documentation that:

content_available - On iOS, use this field to represent content-available in the APNs payload. When a notification or message is sent and this is set to true, an inactive client app is awoken, and the message is sent through APNs as a silent notification and not through the FCM connection server.

In order to send notifications via APN, I have tried to send push notifications using content_available: true, but I cannot reproduce a NotRegistered token error on IOS. It still returns a success message.

I'm sending notifications using sendMulticast. my payload:

const payload = {
  notification: {
      title: text,
  },
  android: {
      priority: "high",
      ttl: 60 * 60 * 1,
      collapseKey: "yo",
      notification: {
          channel_id: 'YO',
          tag: userDoc.id,
      },
  },
  apns: {
      payload: {
          aps: {
              sound: "reminder.caf",
              "content-available": 1,
          }
      },
      headers: {
          "apns-collapse-id": "yo",
          "apns-priority": "10"
      }
  },
  priority: 10
}

I also cannot reproduce a NotRegistered token response via an HTTP request:

curl -X POST \
  https://fcm.googleapis.com/fcm/send \
  -H 'authorization: key=server_key_here' \
  -H 'content-type: application/json' \
  -d '{
  "to": "fcm_token_here", 
  "priority": "high",
  "content_available": true,
  "notification": {
    "empty": "body"
  },
  "data": {
    "key1": ""
  }
}'

Bottom Line

1. How do I detect IOS uninstalls using FCM?
2. And if it's not possible, how can I detect uninstalls on IOS?

1 Answers

Well, depends on your demand. Your questions's answer is slient push not normal push.

A background notification is a remote notification that doesn’t display an alert, play a sound, or badge your app’s icon. It wakes your app in the background and gives it time to initiate downloads from your server and update its content. Apple Document


Important

The system treats background notifications as low priority: you can use them to refresh your app’s content, but the system doesn’t guarantee their delivery. In addition, the system may throttle the delivery of background notifications if the total number becomes excessive. The number of background notifications allowed by the system depends on current conditions, but don’t try to send more than two or three per hour.

Silent push notifications will not work when the device is in “Low Data Mode“.

Slient Push Notification Payload Example.

  {
   "aps" : {
      "content-available" : 1
   },
   "acme1" : "bar",
   "acme2" : 42
}

You have to use "content-available" : 1 in payload for slient push.

On the other hand, if your client running on iOS 12.3 or later Deletions metric

Related