invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.72k stars 2.22k forks source link

[🐛] onMessage triggers twice on notification ios #6982

Closed AuroPick closed 1 year ago

AuroPick commented 1 year ago

Issue

onMessage triggers twice when receive notification on iOS

NotificationListener.js

import { memo, useCallback, useEffect } from 'react'

import notifee, { EventType } from '@notifee/react-native'
import messaging from '@react-native-firebase/messaging'
import { useNavigation } from '@react-navigation/core'
import { useUpdateAtom } from 'jotai/utils'
import { Linking } from 'react-native'

import { useAnalytics } from '../hooks'
import { addGiftedChatFieldsToEachMessage } from '../screen/Loader/data-operations'
import { chatsAtom } from '../utils/atoms'
import * as Requests from '../utils/requests'
import Storage from '../utils/storage'

const NotificationListenerComponent = () => {
  // hooks
  const navigation = useNavigation()

  const setChats = useUpdateAtom(chatsAtom)

  const { logNotificationOpen } = useAnalytics()

  // callbacks
  const setLastReceivedMessageDates = useCallback(async (chatId, createdAt) => {
    const lastReceivedMessageDates = await Storage.getItem('lastReceivedMessageDates', {})

    lastReceivedMessageDates[chatId] = createdAt
    Storage.setItem('lastReceivedMessageDates', lastReceivedMessageDates)
  }, [])

  const navigateToChat = useCallback(
    async (chatId) => {
      if (!chatId) return

      const chats = await Storage.getItem('chats')
      const user = await Storage.getItem('user')

      if (!chats || !user) return

      let currentChat = chats[chatId]

      if (!currentChat) {
        const { hasChat, chat } = await Requests.getChatById({ chatId })

        if (!hasChat) return

        const messages = addGiftedChatFieldsToEachMessage(chat)

        setLastReceivedMessageDates(chat._id, messages[messages.length - 1].createdAt)

        setChats((data) => {
          const set = { ...data, [chat._id]: { ...chat, messages } }

          Storage.setItem('chats', set)

          return set
        })

        currentChat = { ...chat, messages }
      }

      const params = {
        chatId,
        matchId: currentChat.match._id,
        otherUser: currentChat.user1._id === user._id ? currentChat.user2 : currentChat.user1,
        item: currentChat
      }

      navigation.navigate('Chat', params)
    },
    [navigation, setLastReceivedMessageDates]
  )

  const handler = useCallback(
    async (notification) => {
      logNotificationOpen({ notificationId: notification?.data?.notificationId })

      if (notification?.data?.deeplink) {
        const canOpen = await Linking.canOpenURL(notification?.data?.deeplink)

        if (canOpen) Linking.openURL(notification?.data?.deeplink)
      }

      if (notification?.data?.link?.includes('gokarma://chat/')) {
        const chatId = notification.data.link.replace('gokarma://chat/', '')

        navigateToChat(chatId)
      }
    },
    [navigateToChat, logNotificationOpen]
  )

  const handleFirebaseForeground = useCallback((notification) => {
    if (!notification?.data?.link?.includes('gokarma://chat/')) {
      notifee.displayNotification({
        title: notification?.notification?.title,
        body: notification?.notification?.body,
        android: {
          channelId: 'default',
          smallIcon: 'ic_stat_name'
        },
        data: notification?.data
      })
    }
  }, [])

  const handleNotifeeForeground = useCallback(
    ({ type, detail }) => {
      switch (type) {
        case EventType.PRESS:
          handler(detail.notification)
          break
        default:
          break
      }
    },
    [handler]
  )

  useEffect(() => {
    const firebaseOpenSubscription = messaging().onNotificationOpenedApp(handler)
    const firebaseForegroundSubscription = messaging().onMessage(handleFirebaseForeground)
    const notifeeForegroundSubscription = notifee.onForegroundEvent(handleNotifeeForeground)

    return () => {
      firebaseOpenSubscription()
      firebaseForegroundSubscription()
      notifeeForegroundSubscription()
    }
  }, [handler, handleFirebaseForeground, handleNotifeeForeground])

  return null
}

export const NotificationListener = memo(NotificationListenerComponent)

BottomNavigation.js


const Tab = createBottomTabNavigator()

const BottomNavigation = ({
  navigation,
  route: {
    params: { link }
  }
}) => {

  return (
    <>
      <Tab.Navigator>
...
      </Tab.Navigator>
      <NotificationListener />
    </>
  )
}

const styles = StyleSheet.create({
  bannerAdContainer: {
    backgroundColor: colors.WHITE
  }
})

export default BottomNavigation

console output Screenshot 2023-03-10 at 17 45 27


Project Files

Javascript

Click To Expand

#### `package.json`: ```json { "name": "GoKarma", "version": "0.0.1", "androidV": "2.17.0", "iosV": "2.17.0", "private": true, "rnpm": { "assets": [ "src/fonts" ] }, "scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "start": "react-native start", "build": "build.sh", "build:macos": "sh build.sh", "test": "jest", "lint": "eslint \"**/*.{js,jsx,ts,tsx}\" --quiet --fix", "format": "prettier --check ./src", "format:fix": "prettier --write ./src", "postinstall": "cd node_modules/react-native-gifted-chat && yarn install && yarn lint && yarn build && yarn config:npm && rm -rf node_modules && cd ../.. && yarn patch", "patch": "patch-package", "pod": "cd ios && pod install --repo-update && cd ..", "pod:silicon": "cd ios && arch -x86_64 pod install --repo-update && cd ..", "pod:clear": "cd ios && pod deintegrate && rm -rf Podfile.lock && cd ..", "gradle:clear:macos": "cd android && ./gradlew clean && cd .." }, "dependencies": { "@babel/preset-typescript": "^7.16.7", "@fastify/deepmerge": "^1.3.0", "@gorhom/bottom-sheet": "4.1.5", "@invertase/react-native-apple-authentication": "^2.2.2", "@miblanchard/react-native-slider": "1.5.0", "@notifee/react-native": "^5.7.0", "@react-native-async-storage/async-storage": "1.17.7", "@react-native-community/blur": "^4.3.0", "@react-native-community/clipboard": "^1.5.1", "@react-native-community/hooks": "^2.6.0", "@react-native-community/netinfo": "^6.0.0", "@react-native-firebase/analytics": "^14.8.0", "@react-native-firebase/app": "^14.8.0", "@react-native-firebase/auth": "^14.8.0", "@react-native-firebase/dynamic-links": "^14.8.0", "@react-native-firebase/in-app-messaging": "^14.8.0", "@react-native-firebase/messaging": "^14.8.0", "@react-native-google-signin/google-signin": "^7.0.1", "@react-navigation/bottom-tabs": "^6.3.1", "@react-navigation/core": "^6.2.1", "@react-navigation/elements": "^1.3.1", "@react-navigation/material-top-tabs": "^6.0.0", "@react-navigation/native": "^6.0.10", "@react-navigation/native-stack": "^6.0.0", "@react-navigation/stack": "^6.2.1", "@stackbuilders/react-native-spotlight-tour": "https://github.com/GO-Karma/react-native-spotlight-tour", "@up-inside/react-native-admost": "^2.0.2", "@welldone-software/why-did-you-render": "^6.1.1", "axios": "^0.21.1", "bson": "^4.3.0", "compare-versions": "^3.6.0", "dayjs": "^1.10.8", "grapheme-splitter": "^1.0.4", "i18next": "^21.8.14", "jotai": "1.8.5", "lodash": "^4.17.21", "lottie-react-native": "^5.1.4", "moment": "^2.29.1", "optics-ts": "^2.3.0", "query-string": "^7.0.1", "react": "18.0.0", "react-error-boundary": "^3.1.3", "react-hook-form": "^7.4.0", "react-i18next": "^11.18.3", "react-native": "0.69.4", "react-native-adapty": "^1.3.13", "react-native-admob-native-ads": "0.6.0", "react-native-android-location-enabler": "^1.2.2", "react-native-branch": "^5.4.0", "react-native-circular-progress": "^1.3.7", "react-native-circular-progress-indicator": "https://github.com/GO-Karma/react-native-circular-progress-indicator", "react-native-circular-progress-indicator-latest": "npm:react-native-circular-progress-indicator", "react-native-collapsible": "^1.6.0", "react-native-confetti-cannon": "^1.5.2", "react-native-config": "^1.4.2", "react-native-countdown-component": "^2.7.1", "react-native-country-picker-modal": "^2.0.0", "react-native-date-picker": "^4.2.5", "react-native-device-info": "^8.3.1", "react-native-easing-gradient": "^1.0.0", "react-native-fast-image": "^8.5.11", "react-native-fbsdk-next": "^11.1.0", "react-native-flash-message": "^0.1.23", "react-native-geolocation-service": "^5.3.0-beta.2", "react-native-gesture-flip-card": "^1.0.5", "react-native-gesture-handler": "2.5.0", "react-native-get-random-values": "^1.7.0", "react-native-gifted-chat": "https://github.com/GO-Karma/react-native-gifted-chat", "react-native-google-mobile-ads": "^8.2.3", "react-native-gradle-plugin": "^0.71.0", "react-native-iap": "^7.5.0", "react-native-image-crop-picker": "0.37.3", "react-native-image-pan-zoom": "^2.1.12", "react-native-in-app-review": "^3.2.2", "react-native-indicators": "^0.17.0", "react-native-keyboard-aware-scroll-view": "^0.9.4", "react-native-keychain": "^8.1.1", "react-native-keycode": "^1.1.2", "react-native-kochava-tracker": "^2.1.1", "react-native-linear-gradient": "^2.5.6", "react-native-localize": "^2.0.3", "react-native-modal": "^13.0.1", "react-native-modals": "https://github.com/GO-Karma/react-native-modals", "react-native-onesignal": "4.3.8", "react-native-pager-view": "^5.4.0", "react-native-permissions": "^3.0.4", "react-native-quick-base64": "^2.0.5", "react-native-raw-bottom-sheet": "^2.2.0", "react-native-reanimated": "2.9.1", "react-native-redash": "^16.2.3", "react-native-responsive-fontsize": "^0.5.1", "react-native-responsive-screen": "1.4.2", "react-native-restart": "^0.0.22", "react-native-safe-area-context": "^4.2.4", "react-native-screens": "3.15.0", "react-native-share": "^7.3.0", "react-native-shimmer": "^0.6.0", "react-native-shimmer-placeholder": "^2.0.8", "react-native-splash-screen": "^3.2.0", "react-native-svg": "^12.4.3", "react-native-swiper": "^1.6.0", "react-native-tab-view": "^3.1.1", "react-native-toast-message": "^2.1.3", "react-native-track-player": "^3.0.0", "react-native-url-polyfill": "^1.3.0", "react-native-uuid": "^2.0.1", "react-native-vector-icons": "^8.1.0", "react-native-walkthrough-tooltip": "https://github.com/GO-Karma/react-native-walkthrough-tooltip", "react-native-webview": "^11.6.5", "react-query": "^3.13.10", "recyclerlistview": "^3.0.5", "rn-fetch-blob": "^0.12.0", "rollbar-react-native": "^0.9.2", "socket.io-client": "4.5.1", "tinycolor2": "^1.4.2", "toggle-switch-react-native": "^3.2.0", "use-double-tap": "^1.3.3", "utm-latlng": "^1.0.6", "validator": "^13.6.0" }, "devDependencies": { "@babel/core": "7.12.10", "@babel/preset-env": "^7.18.9", "@babel/runtime": "7.12.5", "@types/socket.io-client": "^1.4.36", "babel-jest": "25.5.1", "babel-plugin-module-resolver": "^4.1.0", "babel-plugin-transform-remove-console": "^6.9.4", "eslint": "^8.8.0", "eslint-config-airbnb": "^19.0.4", "eslint-config-prettier": "^8.3.0", "eslint-plugin-import": "^2.25.3", "eslint-plugin-jsx-a11y": "^6.5.1", "eslint-plugin-react": "^7.28.0", "eslint-plugin-react-hooks": "^4.3.0", "eslint-plugin-react-native": "^4.0.0", "jest": "25.5.4", "metro-react-native-babel-preset": "0.70.3", "patch-package": "^6.4.7", "postinstall-postinstall": "^2.1.0", "prettier": "^2.5.1", "react-test-renderer": "18.0.0" }, "jest": { "preset": "react-native" } } ``` #### `firebase.json` for react-native-firebase v6: ```json { "react-native": { "android_task_executor_maximum_pool_size": 10, "android_task_executor_keep_alive_seconds": 3 } } ```

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby require_relative '../node_modules/react-native/scripts/react_native_pods' require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' platform :ios, '12.4' install! 'cocoapods', :deterministic_uuids => false production = ENV["PRODUCTION"] == "1" target 'GoKarma' do config = use_native_modules! # Flags change depending on the env values. flags = get_default_flags() use_react_native!(:path => config["reactNativePath"], # to enable hermes on iOS, change `false` to `true` and then install pods :production => production, :hermes_enabled => true, :fabric_enabled => flags[:fabric_enabled], :flipper_configuration => FlipperConfiguration.enabled, # An absolute path to your application root. :app_path => "#{Pod::Config.instance.installation_root}/.." ) permissions_path = '../node_modules/react-native-permissions/ios' pod 'Permission-AppTrackingTransparency', :path => "#{permissions_path}/AppTrackingTransparency" pod 'Permission-Camera', :path => "#{permissions_path}/Camera" pod 'Permission-LocationWhenInUse', :path => "#{permissions_path}/LocationWhenInUse" pod 'Permission-MediaLibrary', :path => "#{permissions_path}/MediaLibrary" pod 'Permission-Notifications', :path => "#{permissions_path}/Notifications" pod 'Permission-PhotoLibrary', :path => "#{permissions_path}/PhotoLibrary" pod 'AMRAdapterAdmob', '9.12.0.0' pod 'AMRAdapterAdmost', '1.6.7.0' pod 'AMRAdapterFacebook', '6.12.0.1' pod 'AMRAdapterUnity', '4.5.0.0' pod 'AMRAdapterVungle', '6.12.1.0' pod 'AMRAdapterMintegral', '7.2.9.0' # #region react-native-admob-native-ads pod dependencies pod 'FBAudienceNetwork', :podspec => './pod-patch/.patched/FBAudienceNetwork/6.12.0/FBAudienceNetwork.podspec.json' pod 'Google-Mobile-Ads-SDK', '9.12.0' pod 'GoogleMobileAdsMediationFacebook', '6.12.0.0' # #endregion target 'GoKarmaTests' do inherit! :complete # Pods for testing end post_install do |installer| react_native_post_install(installer) __apply_Xcode_12_5_M1_post_install_workaround(installer) installer.pods_project.build_configurations.each do |config| config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64" end installer.pods_project.targets.each do |target| if target.respond_to?(:product_type) and target.product_type == "com.apple.product-type.bundle" target.build_configurations.each do |config| config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO' end end end fix_library_search_paths(installer) end end target 'GoKarma-tvOS' do # Pods for GoKarma-tvOS target 'GoKarma-tvOSTests' do inherit! :search_paths # Pods for testing end end target 'OneSignalNotificationServiceExtension' do pod 'OneSignalXCFramework', '>= 3.0', '< 4.0' end def fix_library_search_paths(installer) def fix_config(config) lib_search_paths = config.build_settings["LIBRARY_SEARCH_PATHS"] if lib_search_paths if lib_search_paths.include?("$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)") || lib_search_paths.include?("\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"") # $(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME) causes problem with Xcode 12.5 + arm64 (Apple M1) # since the libraries there are only built for x86_64 and i386. lib_search_paths.delete("$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)") lib_search_paths.delete("\"$(TOOLCHAIN_DIR)/usr/lib/swift-5.0/$(PLATFORM_NAME)\"") if !(lib_search_paths.include?("$(SDKROOT)/usr/lib/swift") || lib_search_paths.include?("\"$(SDKROOT)/usr/lib/swift\"")) # however, $(SDKROOT)/usr/lib/swift is required, at least if user is not running CocoaPods 1.11 lib_search_paths.insert(0, "$(SDKROOT)/usr/lib/swift") end end end end projects = installer.aggregate_targets .map{ |t| t.user_project } .uniq{ |p| p.path } .push(installer.pods_project) projects.each do |project| project.build_configurations.each do |config| fix_config(config) end project.native_targets.each do |target| target.build_configurations.each do |config| fix_config(config) end end project.save() end end ``` #### `AppDelegate.m`: ```objc #import "AppDelegate.h" #if RCT_DEV #import #endif #import #import #import #import #import #import #import #import #import // #import "RNSplashScreen.h" #import #if RCT_NEW_ARCH_ENABLED #import #import #import #import #import #import #import static NSString *const kRNConcurrentRoot = @"concurrentRoot"; @interface AppDelegate () { RCTTurboModuleManager *_turboModuleManager; RCTSurfacePresenterBridgeAdapter *_bridgeAdapter; std::shared_ptr _reactNativeConfig; facebook::react::ContextContainer::Shared _contextContainer; } @end #endif @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { RCTAppSetupPrepareApp(application); RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; #if RCT_NEW_ARCH_ENABLED _contextContainer = std::make_shared(); _reactNativeConfig = std::make_shared(); _contextContainer->insert("ReactNativeConfig", _reactNativeConfig); _bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:bridge contextContainer:_contextContainer]; bridge.surfacePresenter = _bridgeAdapter.surfacePresenter; #endif [[Branch getInstance] delayInitToCheckForSearchAds]; [[Branch getInstance] disableCookieBasedMatching]; // Uncomment this line to use the test key instead of the live one. // [RNBranch useTestInstance]; [RNBranch initSessionWithLaunchOptions:launchOptions isReferrable:YES]; // <-- add this // facebook sdk init [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions]; // ß[RNSplashScreen show]; if([FIRApp defaultApp] == nil){ [FIRApp configure]; } [RollbarReactNative initWithAccessToken:@""]; #if RCT_DEV [bridge moduleForClass:[RCTDevLoadingView class]]; #endif NSDictionary *initProps = [self prepareInitialProps]; UIView *rootView = RCTAppSetupDefaultRootView(bridge, @"GoKarma", initProps); if (@available(iOS 13.0, *)) { rootView.backgroundColor = [UIColor systemBackgroundColor]; } else { rootView.backgroundColor = [UIColor whiteColor]; } self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIViewController *rootViewController = [UIViewController new]; rootViewController.view = rootView; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; return YES; } /// This method controls whether the `concurrentRoot`feature of React18 is turned on or off. /// /// @see: https://reactjs.org/blog/2022/03/29/react-v18.html /// @note: This requires to be rendering on Fabric (i.e. on the New Architecture). /// @return: `true` if the `concurrentRoot` feture is enabled. Otherwise, it returns `false`. - (BOOL)concurrentRootEnabled { // Switch this bool to turn on and off the concurrent root return true; } - (NSDictionary *)prepareInitialProps { NSMutableDictionary *initProps = [NSMutableDictionary new]; #ifdef RCT_NEW_ARCH_ENABLED initProps[kRNConcurrentRoot] = @([self concurrentRootEnabled]); #endif return initProps; } - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge { #if DEBUG return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; #else return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; #endif } #if RCT_NEW_ARCH_ENABLED #pragma mark - RCTCxxBridgeDelegate - (std::unique_ptr)jsExecutorFactoryForBridge:(RCTBridge *)bridge { _turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge delegate:self jsInvoker:bridge.jsCallInvoker]; return RCTAppSetupDefaultJsExecutorFactory(bridge, _turboModuleManager); } #pragma mark RCTTurboModuleManagerDelegate - (Class)getModuleClassFromName:(const char *)name { return RCTCoreModulesClassProvider(name); } - (std::shared_ptr)getTurboModule:(const std::string &)name jsInvoker:(std::shared_ptr)jsInvoker { return nullptr; } - (std::shared_ptr)getTurboModule:(const std::string &)name initParams: (const facebook::react::ObjCTurboModule::InitParams &)params { return nullptr; } - (id)getModuleInstanceFromClass:(Class)moduleClass { return RCTAppSetupDefaultModuleFromClass(moduleClass); } #endif - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary *)options { NSDictionary* infoDict = [[NSBundle mainBundle] infoDictionary]; NSString* fbappid = [infoDict objectForKey:@"FacebookAppID"]; [FBAEMReporter configureWithNetworker:nil appID:fbappid reporter:nil]; [FBAEMReporter enable]; [FBAEMReporter handleURL:url]; if ([RNBranch application:application openURL:url options:options]) { // do other deep link routing for the Facebook SDK, Pinterest SDK, etc if ([[FBSDKApplicationDelegate sharedInstance] application:application openURL:url options:options]) { return YES; } } return [RCTLinkingManager application:application openURL:url options:options]; } // Only if your app is using [Universal Links](https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/AppSearch/UniversalLinks.html). - (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler { return [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler]; } @end ```


Android

Click To Expand

#### Have you converted to AndroidX? - [ ] my application is an AndroidX application? - [ ] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [ ] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`: ```groovy // N/A ``` #### `android/app/build.gradle`: ```groovy // N/A ``` #### `android/settings.gradle`: ```groovy // N/A ``` #### `MainApplication.java`: ```java // N/A ``` #### `AndroidManifest.xml`: ```xml ```


Environment

Click To Expand

**`react-native info` output:** ``` System: OS: macOS 13.0.1 CPU: (8) arm64 Apple M1 Memory: 83.98 MB / 8.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 19.7.0 - /opt/homebrew/bin/node Yarn: 1.22.15 - /opt/homebrew/bin/yarn npm: 9.5.0 - /opt/homebrew/bin/npm Watchman: 2023.02.27.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.12.0 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1 Android SDK: API Levels: 29, 31, 33 Build Tools: 30.0.3, 31.0.0, 32.1.0 System Images: android-31 | Google Play ARM 64 v8a Android NDK: Not Found IDEs: Android Studio: 2021.1 AI-211.7628.21.2111.8309675 Xcode: 14.1/14B47b - /usr/bin/xcodebuild Languages: Java: 11.0.14.1 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.0.0 => 18.0.0 react-native: 0.69.4 => 0.69.4 react-native-macos: Not Found npmGlobalPackages: *react-native*: Not Found ``` - **Platform that you're experiencing the issue on**: - [ ] iOS - [ ] Android - [ ] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - `e.g. 5.4.3` - **`Firebase` module(s) you're using that has the issue:** - `e.g. Instance ID` - **Are you using `TypeScript`?** - `Y/N` & `VERSION`


github-actions[bot] commented 1 year ago

Hello 👋, to help manage issues we automatically close stale issues.

This issue has been automatically marked as stale because it has not had activity for quite some time.Has this issue been fixed, or does it still require attention?

This issue will be closed in 15 days if no further activity occurs.

Thank you for your contributions.

juanmanuelrot commented 1 year ago

Hi @AuroPick , did you manage to solve it? Having the same issue as soon as I install react-native-onesignal

AuroPick commented 1 year ago

Hi @AuroPick , did you manage to solve it? Having the same issue as soon as I install react-native-onesignal

Hi @juanmanuelrot

I couldn't but I managed to solve it using the id parameter.

I use notifee to show notifications when app is in foreground state, you can give id parameter to notifee and it won't show the notification twice

const handleFirebaseForeground = useCallback((notification) => {
    if (!notification?.data?.link?.includes('gokarma://chat/')) {
      notifee.displayNotification({
        title: notification?.notification?.title,
        body: notification?.notification?.body,
        android: {
          channelId: 'default',
          smallIcon: 'ic_stat_name'
        },
        data: notification?.data,
        id: notification?.messageId  // here
      })
    }
  }, [])
pavelustenko commented 11 months ago

It wont't show it twice in notification center, but in some cases it pops up twice.

HoaiHuynh commented 8 months ago

but in some cases it pops up twice

I'm having the same issue, have you solved it?

parthshiroya6 commented 6 months ago

I was also facing this issue. but now its solve it. please check it you screen use can add onMessage function is inside any addEventListener or any other listener so please add outside of it because sometime they call twice or more time.

Before

async componentDidMount() {
    NetInfo.addEventListener(state => {
  const {details, isConnected, isInternetReachable} = state;
   ....,
   this.notificationFB();
      }
  }

After

async componentDidMount() {
    NetInfo.addEventListener(state => {
  const {details, isConnected, isInternetReachable} = state;
     ....
    }
   this.notificationFB();
  }

then issue resolve in my case.