onNotification not called when the app is first opened from notification tap
See original GitHub issueBug
Environment info
react-native info
output:
ystem:
OS: macOS 10.15.7
CPU: (4) x64 Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz
Memory: 35.33 MB / 8.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 12.20.1 - /usr/local/bin/node
Yarn: 1.22.5 - /usr/local/bin/yarn
npm: 6.14.10 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.10.1 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 14.4, DriverKit 20.2, macOS 11.1, tvOS 14.3, watchOS 7.2
Android SDK:
API Levels: 29, 30
Build Tools: 28.0.3, 29.0.2, 29.0.3
Android NDK: Not Found
IDEs:
Android Studio: 4.1 AI-201.8743.12.41.7199119
Xcode: 12.4/12D4e - /usr/bin/xcodebuild
Languages:
Java: 1.8.0_121 - /usr/bin/javac
Python: 2.7.15 - /Library/Frameworks/Python.framework/Versions/2.7/bin/python
npmPackages:
@react-native-community/cli: Not Found
react: 16.14.0 => 16.14.0
react-native: 0.62.2 => 0.62.2
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
Library version: 7.2.3
Steps To Reproduce
onNotification: function (notification) {
// do something
}
The above code only runs when the notification is tapped and if the app was previously opened. However, if the app was not opened, it never runs.
I’m trying to handle the case when the user taps on the notification and the app wasn’t opened / was killed, in order to react to it accordingly.
I see from RN logs that an initialProps
object is added when the app opens from the notification on iOS, could this be used to add extra info?
Thanks!
Issue Analytics
- State:
- Created 2 years ago
- Reactions:4
- Comments:15 (5 by maintainers)
Top Results From Across the Web
Android react-native-push-notification onNotification not called ...
When I click the notification (app is running in the background), it opens the app but does not call onNotification.
Read more >Tapping on notification to open app not w… - Apple Community
It seems like you're not able to tap on notification to open apps on your iPhone and you came to us from a...
Read more >Start an Activity from a Notification - Android Developers
Tapping Back should take the user back through the app's normal work flow to the Home screen, and opening the Recents screen should...
Read more >react-native-push-notification - npm
If not using a built in Android color ( @android:color/{name} ) for the notification_color meta-data item. In android/app/src/main/res/values/ ...
Read more >Receive messages in an Android app - Firebase - Google
A user tap on a notification opens the app launcher by default. ... This is used when no icon is set for incoming...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Landed on the same issue, for remote notifications, the onNotification is not called on tapping the notification. However, it gets called when the notification arrives. Is there any other method that is triggered on clicking the notification from the tray?
OS: Android
The implementation is pretty much the same as mentioned above. I went through many other issues that were reported but could not find a solution for this. Any help is appreciated.
Thanks in advance.
We were using
react-native-bootsplash
and it was working just fine. Then we removed it andonNotification
was no longer called. We tried a few things and eventually we realized (with a little bit of help from this SO answer) that were missing the following in the.MainActivity
:so in total that now looks like this: