Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS double notification while app is in the background #158

Closed
nikolajev-dev opened this issue Sep 25, 2019 · 4 comments
Closed

iOS double notification while app is in the background #158

nikolajev-dev opened this issue Sep 25, 2019 · 4 comments
Labels
bug Something isn't working properly ios relates to iOS platform runtime issue An issue related to app runtime

Comments

@nikolajev-dev
Copy link

Bug report

Current behavior:
While app is in the background and foreground_notification is set to true, receive 2 notifications in status bar instead of one. This is happening only when push notification using APNS token. When push notification with firebase token, with same payload, all works fine.

Receiving 2 notification instead of one while app is in the background

I tested on exaple project, it act the same as on my project

Expected behavior:

Receive one notification while app is running in the background and when receive notification from APNS with foreground_notification key set.
Steps to reproduce:

  1. Run app
  2. Get tocken usnig method getApnsToken
  3. Use apns token to apns push notification

Environment information

  • Cordova CLI version
  • Cordova platform version
    • cordova platform ls
  • Plugins & versions installed in project (including this plugin)
    • cordova plugin ls 6.1.0
  • Dev machine OS and version, e.g.
    • OSX 10.14.4

Runtime issue

  • OS details
    • iOS 12.1,

iOS build issue:

  • Node JS version
    10.15.3
  • XCode version
    10.1

Related code:

{
    "aps":{
        "alert":{
            "body":"Test",
            "title":"Test"
        },
        "content-available":1,
        "category":"NEW_MESSAGE_CATEGORY",
        "badge":2,
        "mutable-content":1,
        "sound":"default"
        },  
    "notification_foreground": true
}
@odai-alali
Copy link

I am having the same problem, were you able to find a solution/workaround?

@nikolajev-dev
Copy link
Author

Not yet. I hope plugin developers will come up with some solutions.

@dpa99c
Copy link
Owner

dpa99c commented Oct 22, 2019

This is caused because you have both "notification_foreground": "true" and "content-available":1 in the message payload.

"notification_foreground": "true" causes the willPresentNotification delegate to trigger a notification.
"content-available":1 causes the didReceiveRemoteNotification delegate to trigger a notification.

TL;DR: Don't use "notification_foreground": "true" and "content-available":1 together in the same message payload.
I will update the docs to make this clear.

@dpa99c
Copy link
Owner

dpa99c commented Oct 22, 2019

After some investigation, I've been able to handle the case where both both "notification_foreground": "true" and "content-available":1 are specified in the message payload.
The above commit handles this to ensure that only one notification is created per message received.

This means that you can now use "content-available":1 to have iOS wake up the app while it's in the background to receive the message payload without user interaction and still have a notification displayed in the message arrives while the app is in the foreground by using "notification_foreground": "true" .

This functionality will be merged to master and published in the next released version to npm.

@dpa99c dpa99c added bug Something isn't working properly ios relates to iOS platform runtime issue An issue related to app runtime labels Oct 22, 2019
@dpa99c dpa99c added the ready for release Something has been implemented and is awaiting release to npm label Nov 7, 2019
@dpa99c dpa99c closed this as completed in cb3dda2 Nov 9, 2019
@dpa99c dpa99c removed the ready for release Something has been implemented and is awaiting release to npm label Nov 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working properly ios relates to iOS platform runtime issue An issue related to app runtime
Projects
None yet
Development

No branches or pull requests

3 participants