Open shimil2017 opened 6 years ago
code looks right to me. What do you mean "getting multiple notification"? callback getting called multiple times? banner showing up multiple time?
Callback getting multiple times.please response as soon as possible.Some time notification coming two times.after console i got that listener calling multiple times.please latest stable version also.should I want to change all linked library when i updating library
no you don't need to change all linked library.
add breakpoint on this.notificationListener = FCM.on(FCMEvent.Notification, async (notif) => {
make sure componentDidMount doesn't get called multiple times.
Callback getting multiple times could happen for iOS with but _notificationType would be different. for android there shouldn't be multiple callbacks
why this is happen on ios? any solutions?
@Torippana any solution you got?
yeah, in my case, it was not react-native-fcm probrem. Rendering multiple times because of the other component, thats why.
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) => {
}
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