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

Push Notification onNotification and onNotificationOpened not called when app is in killed or background state #10371

Closed
3 tasks done
ChengZh98 opened this issue Sep 27, 2022 · 24 comments
Assignees
Labels
Push Notifications Related to Push Notification components React Native React Native related issue

Comments

@ChengZh98
Copy link

Before opening, please confirm:

JavaScript Framework

React Native

Amplify APIs

Push Notifications

Amplify Categories

notifications

Environment information

  System:
    OS: macOS 12.6
    CPU: (10) arm64 Apple M1 Max
    Memory: 185.30 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 17.8.0 - /opt/homebrew/bin/node
    Yarn: 1.22.18 - /opt/homebrew/bin/yarn
    npm: 8.5.5 - /opt/homebrew/bin/npm
  Browsers:
    Chrome: 105.0.5195.125
    Safari: 16.0
  npmGlobalPackages:
    npm: 8.5.5
    yarn: 1.22.18


Describe the bug

When the app is in background/quit state, onNotification and onNotificationOpened is not triggered,
RNPushNotificationMessagingService is not CALLED

Expected behavior

onNotification or onNotificationOpened are triggered

Reproduction steps

Followed this installation guide https://docs.amplify.aws/lib/push-notifications/getting-started/q/platform/js/#setup-for-ios
Sent a notification through aws console or postman

Code Snippet

// Put your code below this line.

Log output

// Put your logs below this line


aws-exports.js

No response

Manual configuration

No response

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

@tannerabread tannerabread self-assigned this Sep 27, 2022
@tannerabread tannerabread added Push Notifications Related to Push Notification components React Native React Native related issue labels Sep 27, 2022
@tannerabread
Copy link
Contributor

This looks identical to #7018

Can you see if this comment helps you out?

I am going to close this issue in favor of the previous one but if you're still having the issue after following that thread, feel free to comment there

@tannerabread tannerabread closed this as not planned Won't fix, can't repro, duplicate, stale Sep 27, 2022
@ChengZh98
Copy link
Author

ChengZh98 commented Sep 27, 2022

Hi, it is still not working, even if i tried the implementation in the comment
Screenshot 2022-09-27 at 14 30 54
onNotification is only triggered when app is in foreground, do i have to do any extra steps in the android manifest?

@tannerabread
Copy link
Contributor

Are you running in to this issue on iOS or android?

Is this on physical devices or on emulators?

@ChengZh98
Copy link
Author

ChengZh98 commented Sep 27, 2022

Im running this on a physical device but in debug mode, im sending notifications from through https://fcm.googleapis.com/fcm/send

@ChengZh98
Copy link
Author

Not sure if it might help, but if i handle the logic in https://github.com/invertase/react-native-firebase/tree/main/packages/messaging it works fine for foreground background but not in quit state

@tannerabread tannerabread reopened this Sep 27, 2022
@tannerabread
Copy link
Contributor

tannerabread commented Sep 27, 2022

Seems to be slightly different from the linked issue as yours is happening for the quit state and for both onNotification and onNotificationOpened

Just curious if you've tried it on your physical device not in debug mode?

@tannerabread tannerabread added the pending-triage Issue is pending triage label Sep 27, 2022
@ChengZh98
Copy link
Author

Hi, yes i tried still no notification

@tannerabread
Copy link
Contributor

A similar issue had the resolution outlined here

I didn't see this step in the guide you followed. It is supposed to auto-configure but may not be for some reason

@ChengZh98
Copy link
Author

Tried to implement with that, but it's still not working

@arthurhts
Copy link

I have the same problem, opened is only called with app minimized. Already with fully closed app it doesn't work on android

@tannerabread
Copy link
Contributor

@ChengZh98 @arthurhts
Which version of pushnotification are you running?
This is currently being tracked as a bug in #7018 and I believe the underlying cause might be the same.
Please let me know if you think there is something different about this issue than that one and I will leave it open. If not I will close this issue and we can track progress on #7018

@arthurhts
Copy link

@tannerabread used version 4.3.18 push-notification

@tannerabread
Copy link
Contributor

tannerabread commented Oct 10, 2022

@arthurhts can you try version (4.3.26) and see if that solves the problem?

this comment asking about the version has not had anyone test if it works

@arthurhts
Copy link

@tannerabread
looking at the version you mentioned there was no change in the push code, Is there any fix in the latest version related to this problem?

@tannerabread
Copy link
Contributor

@arthurhts It seems like there isn't. We are working on triaging the issue though and I'll update this issue when I know more

@tannerabread
Copy link
Contributor

@ChengZh98
Were you seeing this issue on iOS and Android?
I assumed iOS when I first read this issue based on the setup guide you linked but @arthurhts was seeing the problem on Android

@tannerabread
Copy link
Contributor

@ChengZh98 @arthurhts
Can one of you give me the full environment details with

npx envinfo --system --binaries --browsers --npmPackages --duplicates --npmGlobalPackages

@jim-jigx
Copy link

jim-jigx commented Oct 19, 2022

@tannerabread : You didn't ask me specifically but we are having the same problem. Output of above command:

  System:
    OS: macOS 12.6
    CPU: (10) x64 Apple M1 Pro
    Memory: 21.18 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 14.18.2 - /usr/local/bin/node
    Yarn: 3.2.1 - /usr/local/bin/yarn
    npm: 6.14.10 - ~/jigx-com/jigx/node_modules/.bin/npm
    Watchman: 2022.10.03.00 - /usr/local/bin/watchman
  Browsers:
    Chrome: 106.0.5249.119
    Safari: 16.0
  npmPackages:
    @commitlint/cli: ^11.0.0 => 11.0.0 
    @commitlint/config-conventional: ^11.0.0 => 11.0.0 
    @react-native-community/netinfo: * => 6.0.2 
    @rnmapbox/maps: * => 10.0.0-beta.8 
    @sentry/react-native: * => 2.2.1 
    @types/color: ^3.0.1 => 3.0.2 
    @types/d3-array: ^2.8.0 => 2.8.0 
    @types/d3-scale: ^3.2.2 => 3.2.2 
    @types/d3-shape: ^2.0.0 => 2.0.0 (1.3.8)
    @types/jest: ^26.0.19 => 26.0.19 (26.0.24)
    @types/jsonwebtoken: ^8.5.0 => 8.5.0 
    @types/lodash: ^4.14.164 => 4.14.167 (4.14.169, 4.14.175)
    @types/node: ^14.17.32 => 14.17.32 (14.17.0, 16.10.1, 14.14.19)
    @types/object-hash: ^1.3.4 => 1.3.4 
    @types/query-string: ^6.3.0 => 6.3.0 
    @types/react: ^17.0.0 => 17.0.0 (16.14.2)
    @types/react-dom: ^16.9.8 => 16.9.10 
    @types/react-native: ^0.66.4 => 0.66.17 (0.63.43)
    @types/react-native-snap-carousel: ^3.8.2 => 3.8.2 
    @types/react-native-vector-icons: ^6.4.6 => 6.4.6 
    @types/react-native-video: ^5.0.12 => 5.0.12 
    @types/react-redux: ^7.1.5 => 7.1.15 
    @types/react-router-dom: ^5.1.5 => 5.1.7 
    @types/react-test-renderer: 17.0.1 => 17.0.1 (17.0.0)
    @types/sqlite3: ^3.1.7 => 3.1.7 
    @types/uuid: ^8.3.0 => 8.3.0 
    @types/webpack-env: ^1.16.3 => 1.16.3 (1.16.0)
    HelloWorld:  0.0.1 
    bsd-3-module:  0.0.0 
    crypto-js: ^4.1.1 => 4.1.1 (3.3.0)
    custom-license:  0.0.0 
    eslint: 7.32.0 => 7.32.0 (7.31.0)
    eslint-plugin-import: ^2.25.4 => 2.25.4 (2.22.1)
    eslint-plugin-jest: ^26.1.1 => 26.1.1 (24.1.3)
    eslint-plugin-json: ^3.1.0 => 3.1.0 
    eslint-plugin-node: ^11.1.0 => 11.1.0 
    eslint-plugin-promise: ^6.0.0 => 6.0.0 
    eslint-plugin-react: ^7.29.2 => 7.29.2 (7.22.0)
    eslint-plugin-react-hooks: 4.3.0 => 4.3.0 (4.2.0)
    eslint-plugin-react-native: ^4.0.0 => 4.0.0 
    eslint-plugin-standard: ^5.0.0 => 5.0.0 
    hermes-inspector-msggen:  1.0.0 
    html-entities: ^2.3.2 => 2.3.2 (1.4.0)
    husky: ^6.0.0 => 6.0.0 
    invalid-with-comma:  0.0.0 
    jest: 26.6.0 => 26.6.0 
    lerna: ^3.22.1 => 3.22.1 
    license-checker: ^25.0.1 => 25.0.1 
    memo-parser:  undefined (0.2.1)
    private:  0.0.0 
    public-domain-module:  0.0.0 
    react: * => 17.0.2 
    react-fast-compare: https://github.com/jigx-com/react-fast-compare => 3.2.0 
    react-intl: * => 5.10.11 
    react-native: * => 0.68.3 
    react-native-gesture-handler: * => 1.9.0 
    react-native-get-random-values: * => 1.7.2 
    react-native-inappbrowser-reborn: * => 3.5.1 
    react-native-localize: * => 2.1.5 
    react-native-permissions: * => 3.0.5 (2.2.2)
    react-native-safe-area-context: * => 3.1.9 
    react-native-sqlite-storage: * => 6.0.1 
    react-native-svg: * => 12.1.0 
    react-native-webview: * => 11.13.0 
    react-test-renderer: 17.0.2 => 17.0.2 
  npmGlobalPackages:
    @react-native-community/cli: 8.0.4
    aws-cdk: 2.38.0
    corepack: 0.10.0
    jq: 1.7.2
    n: 8.0.1
    npm: 8.4.1
    serverless: 3.3.0

@tannerabread
Copy link
Contributor

@jim-jigx Is this the same problem you mentioned in #10252 ?
If so we are trying to figure out if those are the same cause, that issue seemed to be related to Android 12+

@jim-jigx
Copy link

jim-jigx commented Oct 19, 2022

@jim-jigx Is this the same problem you mentioned in #10252 ? If so we are trying to figure out if those are the same cause, that issue seemed to be related to Android 12+

Yes, this is the same issue on our side. This issue is the symptom we are seeing (onNotification not being called), the #10252 issue is what we see when we debug the notification handler and can see the exception being thrown.

@tannerabread
Copy link
Contributor

@ChengZh98 @jim-jigx @arthurhts
Can someone confirm if you were experiencing this behavior only when trying to send notifications through the FCM console?

After speaking with another engineer, I was informed that sending through the FCM console is unlikely to work because it sends a different type of message than what Amplify is expecting.
The FCM message looks like:

{
  notification: {
    title: 'foo',
    body: 'bar'
  }
}

while Amplify is designed to handle messages objects like:

{
  data: {
    'pinpoint.notification.title': 'foo',
    'pinpoint.notification.body': 'bar'
  }
}

There's no way that we know of that you can send the expected type through the FCM console.

Additionally, when sending messages through the Pinpoint console, it is better to use the Standard Message type instead of the Raw Message type

@jim-jigx
Copy link

@tannerabread : We are not using the FCM console to send messages. We have an AWS lambda function that constructs the message and sends it to Amplify. The message we send look something like:
const gcm = { data: { title: content.title, sound: 'default', message: content.text, content } }

@tannerabread tannerabread changed the title Push Notification onNotification and onNotificationOpened NOT CALLED WHEN APP IS KILLED OR IN BACKGROUND STATE Push Notification onNotification and onNotificationOpened not called when app is in killed or background state Feb 7, 2023
@tannerabread
Copy link
Contributor

Hi @ChengZh98, @jim-jigx, @arthurhts, the fix from #10252 has been released and seems to have solved that issue. If this issue was the same root cause it should be cleared. From my own testing both of these callbacks fire.

Can someone check if it solves this issue as well?

I also never got any android versions in this thread. Can someone verify if this issue was happening on Android SDK 31+

@tannerabread
Copy link
Contributor

I believe this is resolved as of v5.0.13 with PR #10914

If I was wrong about this issue and it's not isolated to Android SDK 31+, please comment so we can reopen and investigate further

@chrisbonifacio chrisbonifacio removed the pending-triage Issue is pending triage label May 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Push Notifications Related to Push Notification components React Native React Native related issue
Projects
None yet
Development

No branches or pull requests

5 participants