I have stuck in a issue.
Using “@react-native-firebase/app”: “^20.3.0”, “@react-native-firebase/messaging”: “^20.3.0”, in my react native app .
My goal is to send notification in a quite state app when a particular time happens every thing looks fine.
I’ve my server side api created which i use to call inside the messaging .
I use post man to test notification it works fine i received the dummy notification and also get the conditional notification what I give to in my app code only when I trigger api from postman.
but when I test the app without post man it doesn’t work I am not getting notification .
here is My code which I write in index.js
messaging().setBackgroundMessageHandler(async remoteMessage => {
console.log(‘Message handled in the background!’, remoteMessage);
const fcmTokeN = await AsyncStorage.getItem('fcmToken')
const Latitude = await AsyncStorage.getItem('Latitude1')
const Longitude = await AsyncStorage.getItem('Longitude1')
const coordinates = new Coordinates(Latitude,Longitude);
const params = CalculationMethod.MoonsightingCommittee()
console.log('FCM Token:', fcmTokeN); // Should log the FCM token
console.log(‘Latitude:’, Latitude); // Should log the latitude
console.log(‘Longitude:’, Longitude); // Should log the longitude
const date = new Date()
const prayerTimes = new PrayerTimes(coordinates,date,params);
console.log(prayerTimes)
const dateto = moment(prayerTimes.current).format('h:mm A')
//console.log(dateto)
//console.log(time)
const current = prayerTimes.currentPrayer();
const time = current === ‘fajr’ ? moment(prayerTimes.fajr).format(‘h:mm A’) : current === ‘dhuhr’ ? moment(prayerTimes.dhuhr).format(‘h:mm A’)
: current === ‘asr’ ? moment(prayerTimes.asr).format(‘h:mm A’) : current === ‘maghrib’ ? moment(prayerTimes.maghrib).format(‘h:mm A’) :
current === ‘isha’ ? moment(prayerTimes.isha).format(‘h:mm A’):”
if (fcmTokeN ) {
try {
for (let index = 0; dateto === current ; index++) {
// here dateto will give current time and the variable current will show the time of particular event if it matches for loop will execute
const response = await axios.post('https://server/api/send-notification', {
token: fcmTokeN,
notification: {
title: `${current} prayer time starts at :${time}`,
body: `QuranSurah ${dateto}`
}
});
// return response
break
}
}
catch (error) {
console.error('Error sending notification:', error);
}
} else {
console.log('No FCM token found');
}
});
umer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.