How to use the react-native-firebase.notifications function in react-native-firebase

To help you get started, we’ve selected a few react-native-firebase examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uport-project / uport-mobile / lib / sagas / notifications.js View on Github external
function * getInitialNotification () {
  try {
    // console.log('getInitialNotification')
    const message = yield call([firebase.notifications(), 'getInitialNotification'])
    if (!message) return
    yield handleMessage(message.notification.data)
  } catch (error) {
    console.log(error)
  }
}
github pillarwallet / pillarwallet / src / actions / notificationsActions.js View on Github external
return async (dispatch: Function, getState: Function) => { // eslint-disable-line
    const notificationOpen = await firebase.notifications().getInitialNotification();
    if (notificationOpen) {
      checkForSupportAlert(notificationOpen.notification._data);
      const { type, navigationParams } = processNotification(notificationOpen.notification._data) || {};
      const notificationRoute = NOTIFICATION_ROUTES[type] || null;
      updateNavigationLastScreenState({
        lastActiveScreen: notificationRoute,
        lastActiveScreenParams: navigationParams,
      });
      firebase.notifications().setBadge(0);
    }
    if (notificationsOpenerListener) return;
    notificationsOpenerListener = firebase.notifications().onNotificationOpened((message) => {
      checkForSupportAlert(message.notification._data);
      firebase.notifications().setBadge(0);
      const pathAndParams = getNavigationPathAndParamsState();
      if (!pathAndParams) return;
github evollu / react-native-fcm / Examples / firebase-migration / app / App.js View on Github external
async componentDidMount(){
    // Build a channel
    const channel = new firebase.notifications.Android.Channel('test-channel', 'Test Channel', firebase.notifications.Android.Importance.Max)
    .setDescription('My apps test channel');

    // Create the channel
    firebase.notifications().android.createChannel(channel);

    registerAppListener(this.props.navigation);
    firebase.notifications().getInitialNotification()
      .then((notificationOpen: NotificationOpen) => {
        if (notificationOpen) {
          // Get information about the notification that was opened
          const notif: Notification = notificationOpen.notification;
          this.setState({
            initNotif: notif.data
          })
          if(notif && notif.targetScreen === 'detail'){
            setTimeout(()=>{
              this.props.navigation.navigate('Detail')
            }, 500)
          }
        }
github vikrantnegi / local-reminders / App.js View on Github external
createNotificationChannel = () => {
    // Build a android notification channel
    const channel = new firebase.notifications.Android.Channel(
      'reminder',
      'Reminders Channel',
      firebase.notifications.Android.Importance.High
    ).setDescription('Used for getting reminder notification');

    // Create the android notification channel
    firebase.notifications().android.createChannel(channel);
  };
github voximplant / react-native-demo / src / manager / PushManager.android.js View on Github external
console.log('PushManager: FCM: notification: ' + message.data);
                LoginManager.getInstance().pushNotificationReceived(message.data);
            });

            firebase.messaging().getToken()
                .then(token => {
                    console.log(token);
                    this.pushToken = token;
                })
                .catch(() => {
                    console.warn('PushManager android: failed to get FCM token');
                });

            const channel = new firebase.notifications.Android.Channel('voximplant_channel_id', 'Incoming call channel', firebase.notifications.Android.Importance.Max)
                .setDescription('Incoming call received');
            firebase.notifications().android.createChannel(channel);
        } catch (e) {
            console.warn('React Native Firebase is not set up. Enable google-services plugin at the bottom of the build.gradle file');
        }

    }
github uport-project / uport-mobile / index.android.js View on Github external
.setBody(customNotification.body)
    .setData(message.data)
    .android.setChannelId('main')
    .android.setSmallIcon(customNotification.icon)

  firebase.notifications().displayNotification(notification)
  return Promise.resolve()
}

const channel = new firebase.notifications.Android.Channel(
  'main',
  'Main Channel',
  firebase.notifications.Android.Importance.Max,
).setDescription('Main channel')

firebase.notifications().android.createChannel(channel)

AppRegistry.registerHeadlessTask('RNFirebaseBackgroundMessage', () => bgMessaging)
github uport-project / uport-mobile / index.android.js View on Github external
const bgMessaging = async message => {
  const customNotification = JSON.parse(message.data.custom_notification)
  const notification = new firebase.notifications.Notification()
    .setNotificationId(message.messageId)
    .setTitle(customNotification.title)
    .setBody(customNotification.body)
    .setData(message.data)
    .android.setChannelId('main')
    .android.setSmallIcon(customNotification.icon)

  firebase.notifications().displayNotification(notification)
  return Promise.resolve()
}
github evollu / react-native-fcm / Examples / firebase-migration / app / App.js View on Github external
scheduleLocalNotification() {
    let notification = new firebase.notifications.Notification();
    notification = notification.setNotificationId(new Date().valueOf().toString())
    .setTitle( "Test Notification with action")
    .setBody("Force touch to reply")
    .setSound("bell.mp3")
    .setData({
      now: new Date().toISOString()
    });
    notification.android.setChannelId("test-channel")
    notification.android.setPriority(firebase.notifications.Android.Priority.High)
    notification.android.setSmallIcon("ic_launcher")

    firebase.notifications().scheduleNotification(notification, { fireDate: new Date().getTime() + 5000 })
  }
github rainbow-me / rainbow / src / App.js View on Github external
this.notificationListener = firebase.notifications().onNotification(notification => {
      const route = Navigation.getActiveRouteName();
      if (route === 'ConfirmRequest') {
        const localNotification = new firebase.notifications.Notification()
          .setTitle(notification.title)
          .setBody(notification.body)
          .setData({ ...notification.data, fromLocal: true });
        firebase.notifications().displayNotification(localNotification);
      } else {
        const topic = get(notification, 'data.topic');
        this.onPushNotificationOpened(topic, true);
      }
    });
github Skjutsgruppen / skjutsgruppen-reactnative / app / services / firebase / pushNotification.js View on Github external
if (user && user.id && loggedIn) {
      this.onTokenRefreshListener = firebase.messaging().onTokenRefresh((fcmToken) => {
        storeAppToken(fcmToken, getDeviceId());
      });
      firebase.messaging().getToken().then(appToken => storeAppToken(appToken, getDeviceId()));
    }

    const channel = new firebase.notifications.Android.Channel(
      'skjuts-channel', 'Skjutsgruppen Channel', firebase.notifications.Android.Importance.Max,
    )
      .setDescription('Skjutsgruppen app channel');

    firebase.notifications().removeAllDeliveredNotifications();
    firebase.notifications().android.createChannel(channel);

    this.notificationListener = firebase.notifications().onNotification((notification) => {
      this.showLocalNotification(notification);
    });

    this.messageListener = firebase.messaging().onMessage((message) => {
      const { _data: { custom_notification: customNotification } } = message;
      this.scheduleLocalNotification(customNotification);
    });
  }