phonegap / phonegap-plugin-push

Register and receive push notifications
MIT License
1.94k stars 1.91k forks source link

Trying to replace notifications on iOS (using `notId`) #2617

Open wolfenrain opened 5 years ago

wolfenrain commented 5 years ago

Expected Behaviour

That when using the notId the notification will be replaced on iOS.

Actual Behaviour

I just get a new notifiction instead of the old one replaced.

Reproduce Scenario (including but not limited to)

Send this Android payload using FCM to an Android device:

{
  "delayWhileIdle": false,
  "collapseKey": "testKey",
  "priority": "high",
  "dryRun": false,
  "data": {
    "notId": 851980,
    "color": "#6ECFF6",
    "ledColor": [0, 110, 207, 246],
    "fullscreen": "0",
    "content-available": "1",
    "no-cache": "0",
    "title": "Chat message",
    "body": "Hello",
    },
    "android_channel_id": "channel-chat",
    "priority": 2,
    "soundname": "default"
  }
}

This will go exactly as expected, the notification will be received, if you send it again but with a different body, you will get a replaced notification. As expected

Send this iOS payload using FCM:

{
  "delayWhileIdle": false,
  "collapseKey": "testKey",
  "priority": "high",
  "dryRun": false,
  "data": {
    "notId": 851980,
    "color": "#6ECFF6",
    "ledColor": [0, 110, 207, 246],
    "fullscreen": "0",
    "content-available": "1",
    "no-cache": "0"
  },
  "notification": {
    "title": "Chat message",
    "body": "hello",
    "badge": 2,
    "content-available": "1", // I have tested it with and without this(originally it was without)
    "sound": "default.caf"
  }
}

You will receive a notification, but when you change the body and send the notification again, you get another one instead of it being replaced.

Steps to Reproduce

See Reproduce Scenario.

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

Android 8 and iOS 12.1

(Android) What device vendor (e.g. Samsung, HTC, Sony...)

Motorola

Cordova CLI version and cordova platform version

cordova: 8.0.1-nightly.2018.8.31.dfd2fe79 (cordova-lib@8.0.1-nightly.2018.8.31.d93cfa77) cordova android: 7.1.1 cordova ios: 4.5.5

Plugin version

2.2.3, but with current master code.

Sample Push Data Payload

See Reproduce Scenario.

Sample Code that illustrates the problem

test script to easily test(duh)

#!/usr/bin/env node

var gcm = require('node-gcm');
var sender = new gcm.Sender('serverKey');

var messagePayload = {
    "delayWhileIdle": false,
    "collapseKey": "testKey",
    "priority": "high",
    "dryRun": false,
    "data": {
        "notId": 851980,
        "color": "#6ECFF6",
        "ledColor": [0, 110, 207, 246],
        "fullscreen": "0",
        "content-available": "1",
        "no-cache": "0"
    },
    "notification": {
        "title": "Chat message",
        "body": "hello y",
        "badge": 2,
        "content-available": "1",
        "sound": "default.caf"
    }
};

var message = new gcm.Message(messagePayload);
var regTokens = ['deviceToken'];
sender.send(message, {registrationTokens: regTokens}, function(err, response) {
    if (err) {
        console.error('sender.send: ' + err);
        process.exit();
    }
    console.log(response);
});

Logs taken while reproducing problem

macdonst commented 5 years ago

@wolfenrain notId is a legacy field that this plugin uses on Android. For iOS you should use the tag property. For example:

{
  "delayWhileIdle": false,
  "collapseKey": "testKey",
  "priority": "high",
  "dryRun": false,
  "notification": {
    "title": "Chat message",
    "body": "hello",
    "badge": 2,
    "tag": "my-tag"
  }
}
wolfenrain commented 5 years ago

@macdonst I have done some testing with the tag key included, but haven't succeeded yet.. Not sure if I am still missing something. I could also not find anything about the tag key you mentioned, neither in the PushPlugin docs nor Apple docs, so if you could point me in a direction for that, much obliged.

Here is my current payload:

{
  "delayWhileIdle": false,
  "collapseKey": "testKey",
  "priority": "high",
  "dryRun": false,
  "data": {
    "notId": 2097162,
    "color": "#6ECFF6",
    "ledColor": [0, 110, 207, 246],
    "fullscreen": "0",
    "content-available": "1",
    "no-cache": "0"
    },
  },
  "notification": {
    "title": "Chat message",
    "body": "hello",
    "badge": 1,
    "tag": "2097162"
  },
  "timeToLive": 25
}
mark-veenstra commented 5 years ago

Shouldn't it be apns-collapse-id, see: https://medium.com/the-guardian-mobile-innovation-lab/how-to-replace-the-content-of-an-ios-notification-2d8d93766446