evollu / evollu/react-native-fcm
Sometimes it works, sometimes not...
- Dominant language
- Java
- Stars
- 1.7k
- Forks
- 661
- PR merge metrics
- No merged PRs in 30d
Description
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 (
Welcome to React Native!
To get started, edit index.android.js
Double tap R on your keyboard to reload,{'\n'}Shake or press menu button for dev menu
);
}
_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?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.