-
Notifications
You must be signed in to change notification settings - Fork 2.2k
push notification app badges in v6.x #3419
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
Comments
I have the same problem. Also, on iOS, badges doesn't appear and I have neither vibration/sound for notifications. Just the banner is displayed. |
@boreales sound and vibration work for me, I assume you have set the sound in your notification payload?
|
if I were to add "badge": "1" next to sound, then I will always see the badge showing up as 1...but that's not how I want to handle it, I want to handle it on the client side, for my use case, when the app is in the background, the badge should add up every time a push is received, and when the app comes to the foreground, the badge should be cleared |
is this something I would need to handle using firebase.messaging().onMessage and this library? https://github.com/zo0r/react-native-push-notification |
Yes it works now with the sound param. |
I don't think so. It's not the same library as Firebase. |
Yeah agree, i also need methods for set and get badge counts. V6 |
I think in v5 this was handled with firebase.notifications, but seems like that's not in v6 yet according to #2566, and I guess the only other workarounds are react-native-firebase v5 |
We haven't added this API because we see it as out of scope for messaging. The Android implementation was a wrapper around ShortcutBadger which looks abandoned so we don't want to have to support an underlying library in that state, and also not many Android launchers actually support number badges these days. Technically our API should support setting a badge count via an FCM payload as you can set it on the Firebase console (therefore via other custom methods): Has anyone tried that value to see if it works on iOS? |
@Ehesp thanks, and yes i tried that and it works, but please correct me if i’m wrong, does that mean the server sending out these messages would need to keep track of the message count for every client? what if i want the message count to zero out when the user launches the app? if i were to keep track of that in the client, i would probably need to create a special notification to alter that every time the app receives a push or comes back to foreground? to achieve what i wanna do here, is it better for me to integrate with another third party library like react-native-push-notification and set this value in messaging().onMessage()? i don’t really wanna downgrade to v5 since that’s deprecated |
iOS only supports setting a value, rather than incrementing a value. Assuming you have the API to handle getting/setting badge values, you could do this within the background handler: messaging().setBackgroundMessageHandler(async remoteMessage => {
await someLib.incrementBadgeCount();
}); When the app is open, you could then set the badge count to zero. |
@Ehesp thanks. i shall try that just to clarify, is setBackgroundMessageHandler for android only as it indicates in the doc? and it’s a noop for ios https://rnfirebase.io/reference/messaging#setBackgroundMessageHandler if that’s the case, can you please let me know how i can handle that in ios? can i use onMessage for both platforms? if i don’t want to set the ios count from the sender every time |
Ah that needs to be updated. It should work on iOS, just follow along here: https://rnfirebase.io/messaging/usage#background--quit-state-messages cc @Salakar do we pass the headless prop on to check whether it booted on iOS from background? |
Yeah wow, I even wrote them docs and forgot haha. |
@Ehesp thanks, I tried to set that in my index.js, however I'm not seeing anything in logcat besides this:
here's my index.js
here's how my App.js, the AppContainer is created with react-navigation:
is this only supposed to work with silent push? |
it was some cache, i got this to work finally when i loaded the device using xcode, but it still doesn’t work when i archive it and download it via testflight |
@changLiuUNSW I believe @Ehesp mentioned that this feature is out of scope, so you will need to use some combination of other third party libraries to make that work |
@wzhang2 Do u find any library for Android ? |
I worked around this by adding:
to This is the only thing I was using setBadgeCount for anyway. If you set a badge on the server-side message I think it increments the ios badge anyway |
Could somebody explain to me why this issue was closed? I just upgraded from |
@skizzo I believe the fact RNFBv6 does not support local notification APIs and that in the conversion from RNFBv5 to v6 you need to find a helper library to handle the local notification APIs is documented that is the reason Firebase is a cloud service, messaging is a cloud thing and is supported, but notifications are local device APIs and are out of scope going forward |
@wzhang2 I am facing the same issue, setBackgroundMessageHandler in index.js is not called when the build mode is set to release. It works fine in debug mode. Were you able to find any solution? |
@mikehardy I think what can help is for a suggested third-party library in the docs that can be used for such, @nabilfreeman solution for iOS works fine, what's left is android, looking at Shourtcut Badger but if it appears abandoned then I might be a bit sceptical using it, will try to test on android and see if it works fine though. If you're looking for a way to reset badge at Launch you can use @nabilfreeman solution above for iOS, however, this does not reset the badge count if the app was not in quite-mode at the point of being launched. As for Android, you can check out Shourtcut Badger, hope this helps.
|
I don't see any badge counter on my app icon. Any solution?
|
there is none, which is why i went with version 5.x. quite the dealbreaker. |
Show payload of your notification which you send by using a Firebase admin API. |
@skizzo this is a losing choice, you'll get zero maintenance. Integrate a full 3rd party local device notification library. There are many options, but the v5 notifications package was poorly supported (it's a massive API set and not part of firebase so did not see sufficient attention here) and v5 messaging had many issues with fixes in v6+ #3339 which you will want. Staying on v5 is something I would try to dissuade you from in the strongest terms. But of course, whatever works, it is open source... |
@mikehardy you are obviously right, but as somebody who needs to update an app ASAP and can‘t spend days on finding (and testing) a solution for something that was working before, this is the way to go for now. |
Ios badge is not working for me, the notifications are shown but the badge doesn't increment. Some solution? |
If you want to control badging etc I think you will need a full-featured 3rd party local device notification package. There are at least 3 known working with react-native-firebase - notifee.app, react-native-push-notification, react-native-notifications |
Ahhhh, ok, thank you. |
Hello, have any of you had an issue in which budget counter appears on an android device but they do not go to zero after opening, they just continue increasing?? |
@jonra1993 I have this issue as well |
Hi @CaptainJeff have you found any solution. |
When I had the same issue I found that I simply wasn't asking for the permission to show the badge, after I included that with other permissions everything worked fine. |
I didn't read @mikehardy's comments above close enough he mentioned that they separated the handling of notification receiving and handling. This project no longer "creates" notifications so we need a third party app. I"m using notifee.app and it works as expected (for ios)
|
I am also very particular about terminology. react-native-firebase doesn't receive "notifications", it receives "firebase cloud messages" that contain "payloads", and it is possible that the payload may have a notification component, or just be data-only etc, but without being precise on those terms it's nearly impossible to troubleshoot the 200 ways it can fail because it's not clear exactly which part worked or did not work 😅 |
did u mean:: |
Issue
Describe your issue here
does anyone know how I can make the app badges show up when i receive push notifications? is this something I will need to handle myself? cause I saw that you could handle it with firebase.notification in 5.x versions.
I see that the badge does show up on androids, but its not going away even after I open the app, is this also something that i will need to handle myself?
banner and sound work, just not the badges
for what it’s worth, i’m sending messages to a firebase topic and i’m subscribing to that topic upon app launch, and i’m testing this via testflight and side load apk
I can set the badge from the server, but I think that should be handled from the client
thanks so much
Project Files
Javascript
package.json
:firebase.json
for react-native-firebase v6:# N/A
iOS
Click To Expand
ios/Podfile
:platform :ios, '9.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
target 'App' do
Pods for App
pod 'React', :path => '../node_modules/react-native/'
pod 'React-Core', :path => '../node_modules/react-native/React'
pod 'React-DevSupport', :path => '../node_modules/react-native/React'
pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
pod 'React-RCTWebSocket', :path => '../node_modules/react-native/Libraries/WebSocket'
pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
pod 'react-native-webview', :path => '../node_modules/react-native-webview'
pod 'RNReanimated', :path => '../node_modules/react-native-reanimated'
pod 'RNGestureHandler', :path => '../node_modules/react-native-gesture-handler'
pod 'RNDeviceInfo', :path => '../node_modules/react-native-device-info'
pod 'RNFBApp', :path => '../node_modules/@react-native-firebase/app'
pod 'RNFBMessaging', :path => '../node_modules/@react-native-firebase/messaging'
target 'AppTests' do
inherit! :search_paths
Pods for testing
end
use_native_modules!
end
# N/A
AppDelegate.m
:Android
Click To Expand
Have you converted to AndroidX?
android/gradle.settings
jetifier=true
for Android compatibility?jetifier
for react-native compatibility?android/build.gradle
:android/app/build.gradle
:android/settings.gradle
:MainApplication.java
:AndroidManifest.xml
:Environment
Click To Expand
react-native info
output:react-native-firebase
version you're using that has this issue:e.g. 6.4.0
Firebase
module(s) you're using that has the issue:app, messaging
TypeScript
?N
&VERSION
React Native Firebase
andInvertase
on Twitter for updates on the library.The text was updated successfully, but these errors were encountered: