evollu / evollu/react-native-fcm

Multiple notifcation getting on both ios and androdi

Open
#853 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.7k
Forks
661
PR merge metrics
No merged PRs in 30d

Description

HI
I am getting multiple notifaction .please help me as soon as possible

import {Platform} from 'react-native'
import React, { Component } from 'react'
import { connect } from 'react-redux'
import FCM, {FCMEvent, RemoteNotificationResult, WillPresentNotificationResult, NotificationType} from 'react-native-fcm'
import {pushtokenSending,loginUpdate,latlong} from '../Login/LoginAction'
import {notifcationPressed,notifcationSeened} from './Notification/NotifiAction'
class FCMService extends Component {
constructor(props) {
super(props)
}

componentDidMount() {
//const {id,token}=this.props;
this.notificationListener = FCM.on(FCMEvent.Notification, async (notif) => {

if(notif.opened_from_tray){
if(Platform.OS==='android'){
console.log(notif,this.state.appState);
return; 
}
}
if(notif.local_notification){
return;
}

if(Platform.OS==='ios'){
if(notif.aps.alert){
// alert("loopp")
this.props.notifcationPressed(notif)
return;
}
}else{
if(notif.fcm){
this.props.notifcationPressed(notif)
}
}
//this.showLocalNotification(notif);
FCM.cancelAllLocalNotifications()

})

this.refreshTokenListener = FCM.on(FCMEvent.RefreshToken, (token) => {
// update token in server
if(token&&this.props.id&&this.props.token){
this.props.pushtokenSending({fcmtoken:token,id:this.props.id,token:this.props.token,deviceplatform:Platform.OS==='ios'?'ios':'android'})
}

});

FCM.getInitialNotification().then(notif=>{
console.log(notif);
});

this.requestPermissions()

this.initToken()
}

componentWillUnmount() {
FCM.removeAllDeliveredNotifications()
this.notificationListener.remove();
this.refreshTokenListener.remove();
console.log("component un-mounted")
}

requestPermissions = () => {
if(Platform.OS==='android'){
FCM.requestPermissions();
}else {
FCM.requestPermissions({badge: false, sound: true, alert: true}).then(()=>console.log('granted')).catch(()=>console.tron.log('notification permission rejected'))
}
}

initToken = async () => {
const {id,token}=this.props;
const latestFcmToken = await FCM.getFCMToken().then(token => {
return token
});
if(latestFcmToken&&this.props.id&&this.props.token){
//alert(latestFcmToken)
this.props.pushtokenSending({fcmtoken:latestFcmToken,id:this.props.id,token:this.props.token,deviceplatform:Platform.OS==='ios'?'ios':'android'})
}
// logic for saving sending token to server
}

render(){
return null
}
}

const mapStateToProps=({NotifiReducer,Babies,Login})=>{
const {babyId}=Babies
const {id,token,auth}=Login
const {notidata,noticount}=NotifiReducer
return{
babyId,
id,
token,
notidata,
noticount,

}
}
export default connect(mapStateToProps, {pushtokenSending,notifcationPressed,notifcationSeened})(FCMService)

this is my FCMService component

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.