I am new to react native and am trying to create an app that allows user to listen to podcast that will be posted weekly via a database. Each time that a new podcast has been posted I would like the user to receive a background notification.
I have done some research and have been able to react local notifications that display whenever the app is opened (as shown below) I have been following this tutorial
https://wix.github.io/react-native-notifications/docs/localNotifications
Here is my code
import React from 'react'; import {View} from 'react-native'; import {Notifications} from 'react-native-notifications'; import HomeStack from './app/nav'; export default class App extends React.Component { constructor(props) { super(props); Notifications.registerRemoteNotifications(); Notifications.events().registerNotificationReceivedForeground((notification: Notification, completion) => { console.log(`Notification received in foreground: ${notification.title}: ${notification.body}`); completion({alert: true, sound: false, badge: true}); }); Notifications.events().registerNotificationOpened((notification: Notification, completion) => { console.log(`Notification opened: ${notification.payload}`); completion(); }); } someLocalNotification = Notifications.postLocalNotification({ body: 'Local notification,': title, 'Local Notification:'. //sound, "chime:aiff", category: 'SOME_CATEGORY', userInfo; {}: }); render() { return <View style={{ flex: 1 }}><HomeStack /></View> } }
After doing some research I have found some tutorials to be a bit confusing or do not work. I was wondering what is the best way to create background notifications?
You need to integrate firebase in your project,I am also faced that issue,firebase integration is the solution, to get dynamic notification content when the app is opened or closed. npm i react-native-firebase
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.