0

I'm using React native firebase inAppMessaging but it doesn't work at all. I also use react native push natfication and it works. I don't understand why inAppMessaging doesn't work. Below are the codes in my app file.

i follow the orders in the original documentation and try everything i find on google

import React, {useEffect} from 'react';
import {Linking, InteractionManager} from 'react-native';
import Navigation from './src/navigation/index';
import SystemNavigationBar from 'react-native-system-navigation-bar';
import RNBootSplash from 'react-native-bootsplash';
import firebase from '@react-native-firebase/app';
import messaging from '@react-native-firebase/messaging';
import PushNotification from 'react-native-push-notification';
import {FirebaseMessagingTypes} from '@react-native-firebase/messaging';
import inAppMessaging from '@react-native-firebase/in-app-messaging';
import '@react-native-firebase/installations';

const App = () => {
  useEffect(() => {
    RNBootSplash.hide();
    createChannel();

    messaging().onMessage(async remoteMessage => {
      showNotification(remoteMessage.notification!);
    });
    inAppMessaging().setMessagesDisplaySuppressed(false);

    messaging()
      .getInitialNotification()
      .then(remoteMessage => {
        if (
          remoteMessage?.data &&
          Object.keys(remoteMessage.data).length !== 0
        ) {
          const data = remoteMessage.data;
          const values = Object.values(data);
          const url = values[0];
          Linking.openURL(url);
        }
      });
  }, []);

  const getFID = async () => {
    const installation = await firebase.installations().getId();
    console.log('FID:', installation);
  };

  getFID();

  const createChannel = () => {
    PushNotification.createChannel(
      {
        channelId: 'ChannelID',
        channelName: 'ChannelID',
        vibrate: true,
        playSound: true,
      },
      () => {},
    );
  };
  messaging().setBackgroundMessageHandler(async remoteMessage => {
    if (remoteMessage?.data && Object.keys(remoteMessage.data).length !== 0) {
      const data = remoteMessage.data;
      const values = Object.values(data);
      const url = values[0];
      Linking.openURL(url);
    }
  });
  const showNotification = (
    notification: FirebaseMessagingTypes.Notification,
  ) => {
    PushNotification.localNotification({
      title: notification.title,
      message: notification.body!,
      channelId: 'ChannelID',
      vibrate: true,
      playSound: true,
    });
  };

  SystemNavigationBar.stickyImmersive();
  return <Navigation />;
};

export default App;

android/app/build.gradle

implementation platform('com.google.firebase:firebase-bom:31.2.3')  
implementation 'com.google.firebase:firebase-inappmessaging-display'
implementation 'com.google.firebase:firebase-inappmessaging'
implementation 'com.google.firebase:firebase-analytics'
implementation project(':react-native-push-notification')
salih öz
  • 1
  • 1

0 Answers0