evollu / react-native-fcm

react native module for firebase cloud messaging and local notification
MIT License
1.73k stars 681 forks source link

Sometimes it works, sometimes not... #241

Open RatFou opened 7 years ago

RatFou commented 7 years ago

Hi, I'm using RN 0.39, working on Android version.

I use react-native-fcm to push some news. Sometimes I have the alert I added and sometimes not when the app is in background. I have not this issue if the app is closed.

My code:

import React, { Component } from 'react';
import { AppRegistry, StyleSheet, Text, View } from 'react-native';
import FCM from 'react-native-fcm';

export default class app extends Component {
    componentDidMount() {
        FCM.getFCMToken().then(token => {
            console.log(token)
            // store fcm token in your server
        });
    FCM.subscribeToTopic('Some');
    FCM.on("notification", notif => { this._getNewNotification(notif) });
    FCM.getInitialNotification().then(notif => { this._getNewNotification(notif) });
    }

    render() {
        return (
            <View style={styles.container}>
                <Text style={styles.welcome}>Welcome to React Native!</Text>
                <Text style={styles.instructions}>To get started, edit index.android.js</Text>
                <Text style={styles.instructions}>Double tap R on your keyboard to reload,{'\n'}Shake or press menu button for dev menu</Text>
            </View>
        );
    }

    _getNewNotification(notif) {
        json = JSON.stringify(notif);
        data = JSON.parse(json);
        alert(data.fcm.action);
    }
}

const styles = StyleSheet.create({
    container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', },
    welcome: { fontSize: 20, textAlign: 'center', margin: 10, },
    instructions: { textAlign: 'center', color: '#333333', marginBottom: 5, },
});

AppRegistry.registerComponent('app', () => app);

Do you have any idea to solve this issue please?

evollu commented 7 years ago

try setting the priority of the push notification (the one provided by FCM) and see if it gets delivered quicker?

RatFou commented 7 years ago

Already done, to high :)

evollu commented 7 years ago

add break point in onMessageReceived in MessagingService.java and see if it gets triggered correctly

RatFou commented 7 years ago

Thank you but I'm not a Java developper, I don't know how those breakpoints work :( I searched on Internet and all the time the breakpoints where added in Eclipse or Android studio, but I'm not using those IDE (notepad++).

evollu commented 7 years ago

can you install android studio for debugging? it provides much more information and support than just command line. After all, RN a native app.

RatFou commented 7 years ago

Okay

krishbhattacharyya commented 7 years ago

Hi, @evollu , I am facing the same problem with my emulator. It works properly but somehow after sometime it is not showing the notification message but I got the result in console.

this.notificationListener = FCM.on('notification', (notif) => { console.log(notif);//// I got the result }); }