0

I'm using react-native-firebase in my application. I followed this tutorial and followed all steps in both firebase console and in my App.js but don't get any notification. I got firebase token for my Simulator and iPad too.

My code

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View} from 'react-native';
import firebase, {Notification} from 'react-native-firebase';

const instructions = Platform.select({
  ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu',
  android:
    'Double tap R on your keyboard to reload,\n' +
    'Shake or press menu button for dev menu',
});

type Props = {};
export default class App extends Component<Props> {
    componentDidMount() {
        firebase.messaging().hasPermission()
        .then(enabled => {
            if (enabled) {
                firebase.messaging().getToken().then(token => {
                    console.warn("LOG: ", token);
                })
                // user has permissions
            } else {
                firebase.messaging().requestPermission()
                .then(() => {
                    console.warn("User Now Has Permission")
                })
                .catch(error => {
                    console.warn("Error", error)
                    // User has rejected permissions  
                });
            }
        });

        this.notificationDisplayedListener = firebase.notifications().onNotificationDisplayed((notification: Notification) => {
            console.warn('notification displayed', notification)
        // Process your notification as required
        });
        this.notificationListener = firebase.notifications().onNotification((notification: Notification) => {
            console.warn('notification', notification)
            // Process your notification as required
        });
    }

    componentWillUnmount() {
        this.notificationDisplayedListener();
        this.notificationListener();
    }

    render() {
        return (
            <View style={styles.container}>
                <Text style={styles.welcome}>Welcome to React Native!</Text>
                <Text style={styles.instructions}>To get started, edit App.js</Text>
                <Text style={styles.instructions}>{instructions}</Text>
            </View>
        );
    }
}

Any help is appreciated. Thank you.

Riddhi
  • 755
  • 11
  • 31

0 Answers0