$ react-native init rn_notification
$ yarn add @react-native-firebase/app @react-native-firebase/messaging
Download GoogleService-Info.plist
index.js
import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import messaging from '@react-native-firebase/messaging';
async function requestUserPermission() {
try {
const messageinstance = messaging();
const authStatus = await messageinstance.requestPermission();
const enabled =
authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authStatus === messaging.AuthorizationStatus.PROVISIONAL;
if (enabled) {
await messageinstance.registerDeviceForRemoteMessages();
const token = await messageinstance.getToken();
console.log('token:', token);
}
} catch(error) {
console.log("requestUserPermission -> error", error)
}
}
requestUserPermission();
AppRegistry.registerComponent(appName, () => App);
Next - Android push notification