tranhonghan / rnfirebasev7 Goto Github PK
View Code? Open in Web Editor NEWhandle react native firebase v7
handle react native firebase v7
hi
when send message subscribeToTopic show error below:
[FCMService] getToken rejected [Error: [messaging/unknown] SERVICE_NOT_AVAILABLE]
*please Help me
@tranhonghan
i have a issue, it's my first time using push notifcation on my react project.
the remote foreground notification is success i can receive the notification and i can click it, but when the app is at background/quit state i still get the remote notification but after i clicked it nothing happen.
i do excatly like you do :
createNotificationListeners = (onRegister, onNotification, onOpenNotification) => {
// When the application is running, but in the background
messaging()
.onNotificationOpenedApp(remoteMessage => {
console.log('FCMService onNotificationOpenedApp Notification caused app to open from background state:',remoteMessage)
if (remoteMessage) {
const notification = remoteMessage.notification
onOpenNotification(notification)
// this.removeDeliveredNotification(notification.notificationId)
}
});
// When the application is opened from a quit state.
messaging()
.getInitialNotification()
.then(remoteMessage => {
console.log('FCMService getInitialNotification Notification reopen app at quit state:',remoteMessage)
if (remoteMessage) {
const notification = remoteMessage.notification
onOpenNotification(notification)
// this.removeDeliveredNotification(notification.notificationId)
}
});
// Foreground state messages
this.messageListener = messaging().onMessage(async remoteMessage => {
console.log('FCMService A new FCM message arrived!', remoteMessage);
if (remoteMessage) {
let notification = null
if (Platform.OS === 'ios') {
notification = remoteMessage.data.notification
} else {
notification = remoteMessage.notification
}
onNotification(notification)
}
});
Background : No background message handler has been set. Set a handler via the "setBackgroundMessageHandler" method. where i supposed to place 'setBackgroundMessageHandler'?
quit state :
Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle.
[Wed Mar 10 2021 14:27:08.789] WARN No task registered for key ReactNativeFirebaseMessagingHeadlessTask
localNotificationService.showNotification doesn't create popup when app is in foreground.
useEffect(() => {
fcmService.registerAppWithFCM()
fcmService.register(onRegister, onNotification, onOpenNotification)
localNotificationService.configure(onOpenNotification)
function onRegister(token) {
console.log("[App] onRegister: ", token)
}
function onNotification(notify) {
console.log("[App] onNotification: ", notify)
const options = {
soundName: 'default',
playSound: true,
}
localNotificationService.showNotification(
0,
notify.title,
notify.body,
notify,
options
)
}
Does this setup enable you to get background messages from iOS? I'm having problems getting them.
i just added realm insert code part to insert the arriving notifications to my local db. but it is only works when app is in foreground. it is not working when app is in background. what is the function that call up when notification arrived in background?
`function onNotification(notify) {
//console.log("[App] onNotification: ", notify)
realm.write(() => {
console.log('on notification')
var ID =
realm.objects('notifications').sorted('notify_id', true).length > 0
? realm.objects('notifications').sorted('notify_id', true)[0]
.notify_id + 1
: 1;
realm.create('notifications', {
notify_id: ID,
notify_title: notify.title,
notify_body: notify.body,
notify_time: formatAMPM(new Date),
});
});
const options = {
soundName: 'default',
playSound: true //,
// largeIcon: 'ic_launcher', // add icon large for Android (Link: app/src/main/mipmap)
// smallIcon: 'ic_launcher' // add icon small for Android (Link: app/src/main/mipmap)
}
localNotificationService.showNotification(
0,
notify.title,
notify.body,
notify,
options
)
}`
Platform - iOS
Background Notification works fine. But inside the app I only got this
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.