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

This v8 method is deprecated and will be removed in the next major release as part of move to match Firebase Web modular v9 SDK API. Please use getApp() instead. [Component Stack] #8445

Open
FatihArslan-cmd opened this issue Apr 5, 2025 · 4 comments
Labels

Comments

@FatihArslan-cmd
Copy link

FatihArslan-cmd commented Apr 5, 2025

import { getApp } from '@react-native-firebase/app';
import { getMessaging } from '@react-native-firebase/messaging';
import notifee, { AndroidImportance } from '@notifee/react-native';
import { PermissionsAndroid, Platform } from 'react-native';

const app = getApp();
const messaging = getMessaging(app); 

export const requestUserPermission = async () => {
  if (Platform.OS === 'android') {
    const granted = await PermissionsAndroid.request(
      PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
    );
    if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
      return;
    }
  }

  const authStatus = await messaging.requestPermission(); 
  const enabled =
    authStatus === messaging.AuthorizationStatus.AUTHORIZED || 
    authStatus === messaging.AuthorizationStatus.PROVISIONAL;

  if (enabled) {
    await getFCMToken();
  }
};

export const getFCMToken = async () => {
  const token = await messaging.getToken(); 
  console.log('FCM Token:', token);
  return token;
};

export const setupForegroundNotifications = () => {
  return messaging.onMessage(async remoteMessage => { 
    if (remoteMessage) {
      await notifee.displayNotification({
        title: remoteMessage.notification?.title || 'Notification',
        body: remoteMessage.notification?.body || 'Notification body',
        android: {
          channelId: 'default',
          importance: AndroidImportance.HIGH,
          smallIcon: 'ic_launcher',
          pressAction: {
            id: 'default',
          },
          sound: 'lumos_sound_effect',
        },
      });
    }
  });
};

export const setupBackgroundNotifications = () => {
  messaging.setBackgroundMessageHandler(async remoteMessage => { 
    console.log(remoteMessage);
  });
};

export const checkInitialNotification = async () => {
  const remoteMessage = await messaging.getInitialNotification();
  if (remoteMessage) {
    console.log(remoteMessage);
  }
};

export const createDefaultChannel = async () => {
  await notifee.createChannel({
    id: 'default',
    name: 'Default Channel',
    importance: AndroidImportance.HIGH,
  });
};

import React, { useEffect } from 'react';
import Navigation from './navigation/Navigation.js';
import { theme } from './utils/FontConfig.js';
import { UserProvider } from './context/UserContext.jsx';
import { ToastProvider } from './context/ToastService.jsx';
import { createDefaultChannel, requestUserPermission, setupForegroundNotifications, setupBackgroundNotifications, checkInitialNotification } from './utils/Firebase/notificationHandlers.js';
import { LogBox } from 'react-native';
import { BingoWebSocketProvider } from './context/BingoGameWebsocket.js';
import { ThemeProvider } from './context/ThemeContext.jsx';
import { PaperProvider } from 'react-native-paper'
import ConnectivityListener from './context/ConnectivityListener.jsx';
import './context/i18n'

const App = () => {
  LogBox.ignoreLogs(['Text strings must be rendered within a <Text> component']);
  
  useEffect(() => {
    createDefaultChannel();
    requestUserPermission();
    setupForegroundNotifications();
    setupBackgroundNotifications();
    checkInitialNotification();
  }, []);

  return (
    <BingoWebSocketProvider> 
     <ToastProvider>
      <UserProvider>
        <ThemeProvider>
        <PaperProvider theme={theme}>
          <ConnectivityListener>
          <Navigation />
          </ConnectivityListener>
        </PaperProvider>
        </ThemeProvider>
       </UserProvider>
     </ToastProvider>
   </BingoWebSocketProvider>

  );
};

export default App;


I get the following warning This v8 method is deprecated and will be removed in the next major release as part of move to match Firebase Web modular v9 SDK API. Please use getApp() instead. [Component Stack]

@OgDev-01
Copy link

OgDev-01 commented Apr 5, 2025

Hey @FatihArslan-cmd , From the snippet above, you need to import onMessage, getToken... e.t.c from @react-native-firebase/messaging directly.

Example

import {
  getMessaging,
  getToken,
  onMessage,
  onTokenRefresh,
  setBackgroundMessageHandler,
} from "@react-native-firebase/messaging";

This line remains as is

const app = getApp();
const messaging = getMessaging(app); 

Then update your event listeners and token call to pass the messaging as a params like below

onMessage(messaging, async (remoteMessage) => {
    // Do something here
  });

Replicate this for getToken and the rest of the listeners and you won't get the warnings again.

You should also read more about the modular query from the official docs migration guide https://rnfirebase.io/migrating-to-v22#modular-query
Let me know if this helps 👍

@MichaelVerdon MichaelVerdon added plugin: app-core Firebase Apps / Core internals. platform: all labels Apr 7, 2025
@MichaelVerdon
Copy link
Collaborator

Hi there @FatihArslan-cmd it is just like @OgDev-01 said, make sure to use the Modular API as the original Name-spaced API is being deprecated and we intend on transitioning fully and only to Modular at some point. So for any function you are using, import it as so:

import { your_function } from <appropiate-firebase-module>

@macksal
Copy link

macksal commented Apr 7, 2025

Would it be possible to get jsdoc @deprecated annotations for the methods that are going to be removed? Trying to find them all at runtime is a bit time consuming. Marking them explicitly as deprecated will let people use their tooling to do this migration quickly and easily...

@mikehardy
Copy link
Collaborator

It may take us some time get the jsdocs added but in the mean time you might try enabling strict mode, you'll get stack traces any time you use a deprecated method - I added/used this to get the e2e app internally here migrated - https://rnfirebase.io/migrating-to-v22#enabling-deprecation-strict-modes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants