How to use react-native-notifications - 10 common examples

To help you get started, we’ve selected a few react-native-notifications 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 demokratie-live / democracy-client / src / hocs / PushNotifications.js View on Github external
NotificationsIOS.addEventListener('remoteNotificationsRegistered', this.onPushRegistered);
          NotificationsIOS.addEventListener(
            'remoteNotificationsRegistrationFailed',
            this.onPushRegistrationFailed,
          );
          if (!DeviceInfo.isEmulator()) {
            NotificationsIOS.requestPermissions();
          }

          NotificationsIOS.addEventListener('notificationReceivedForeground', notification => {
            this.onNotificationReceivedForeground(notification.getData());
          });
          NotificationsIOS.addEventListener('notificationReceivedBackground', notification => {
            this.onNotificationReceivedBackground(notification.getData());
          });
          NotificationsIOS.addEventListener('notificationOpened', notification => {
            this.onNotificationOpened(notification.getData());
          });
          break;
        case 'android':
          if (!LISTENERS_ADDED) {
            LISTENERS_ADDED = true;
            NotificationsAndroid.setRegistrationTokenUpdateListener(async deviceToken => {
              // console.log('PUSHLOG: setRegistrationTokenUpdateListener', deviceToken);
              // TODO: Send the token to my server so it could send back push notifications...
              const tokenSucceeded = await client.mutate({
                mutation: ADD_TOKEN,
                variables: {
                  token: deviceToken,
                  os: 'android',
                },
              });
github CMP-Studio / DawnChorus / app / actors / notifications.ios.js View on Github external
// console.log('screen will dim');
          // console.log('setting idle timer disabled to false, notifications.ios.js line 43');
          IdleTimerManager.setIdleTimerDisabled(false);
        }
        this.dispatch(updateSilentSwitchState(silent));
      }
    });

    // Push Notifications Configure
    OneSignal.addEventListener('ids', this.onIds.bind(this));
    OneSignal.addEventListener('received', this.onPushNotificationReceived.bind(this));
    OneSignal.configure();

    // Local Notifications Configure
    NotificationsIOS.addEventListener('notificationReceivedForeground', this.onNotificationReceivedForeground.bind(this));
    NotificationsIOS.addEventListener('notificationReceivedBackground', this.onNotificationReceivedBackground.bind(this));
    NotificationsIOS.addEventListener('notificationOpened', this.onNotificationOpened.bind(this));

    this.snoozeAction = new NotificationAction({
      activationMode: 'background',
      title: 'Snooze',
      identifier: 'SNOOZE_ACTION',
    }, (action, completed) => {
      this.dispatch(snoozeAlarm(action.notification.getData().alarmUUID));
      completed();
    });

    this.stopAction = new NotificationAction({
      activationMode: 'background',
      title: 'Stop',
      identifier: 'STOP_ACTION',
    }, (action, completed) => {
github demokratie-live / democracy-client / src / hocs / PushNotifications.js View on Github external
os: 'android',
                },
              });
              if (tokenSucceeded) {
                await AsyncStorage.setItem('push-token', deviceToken);
              }
            });
            NotificationsAndroid.refreshToken();

            // On Android, we allow for only one (global) listener per each event type.
            NotificationsAndroid.setNotificationReceivedListener(notification => {
              // console.log('PUSHLOG: setNotificationReceivedListener', notification);
              const notificationData = JSON.parse(notification.getData().payload);
              this.onNotificationReceivedForeground(notificationData);
            });
            NotificationsAndroid.setNotificationOpenedListener(notification => {
              // console.log('PUSHLOG: setNotificationOpenedListener', notification);
              const notificationData = JSON.parse(notification.getData().payload);
              this.onNotificationOpened(notificationData);
            });

            PendingNotifications.getInitialNotification().then(notifications => {
              // console.log('PUSHLOG: getInitialNotification', notifications);
              if (notifications) {
                notifications.data.forEach(notification => {
                  const notificationData = JSON.parse(notification.payload);
                  if (notification.opened) {
                    this.onNotificationOpened(notificationData);
                  } else {
                    this.handlePushData(notificationData);
                  }
                });
github demokratie-live / democracy-client / src / hocs / PushNotifications.js View on Github external
}

          NotificationsIOS.addEventListener('notificationReceivedForeground', notification => {
            this.onNotificationReceivedForeground(notification.getData());
          });
          NotificationsIOS.addEventListener('notificationReceivedBackground', notification => {
            this.onNotificationReceivedBackground(notification.getData());
          });
          NotificationsIOS.addEventListener('notificationOpened', notification => {
            this.onNotificationOpened(notification.getData());
          });
          break;
        case 'android':
          if (!LISTENERS_ADDED) {
            LISTENERS_ADDED = true;
            NotificationsAndroid.setRegistrationTokenUpdateListener(async deviceToken => {
              // console.log('PUSHLOG: setRegistrationTokenUpdateListener', deviceToken);
              // TODO: Send the token to my server so it could send back push notifications...
              const tokenSucceeded = await client.mutate({
                mutation: ADD_TOKEN,
                variables: {
                  token: deviceToken,
                  os: 'android',
                },
              });
              if (tokenSucceeded) {
                await AsyncStorage.setItem('push-token', deviceToken);
              }
            });
            NotificationsAndroid.refreshToken();

            // On Android, we allow for only one (global) listener per each event type.
github demokratie-live / democracy-client / src / hocs / PushNotifications.js View on Github external
});
            NotificationsAndroid.refreshToken();

            // On Android, we allow for only one (global) listener per each event type.
            NotificationsAndroid.setNotificationReceivedListener(notification => {
              // console.log('PUSHLOG: setNotificationReceivedListener', notification);
              const notificationData = JSON.parse(notification.getData().payload);
              this.onNotificationReceivedForeground(notificationData);
            });
            NotificationsAndroid.setNotificationOpenedListener(notification => {
              // console.log('PUSHLOG: setNotificationOpenedListener', notification);
              const notificationData = JSON.parse(notification.getData().payload);
              this.onNotificationOpened(notificationData);
            });

            PendingNotifications.getInitialNotification().then(notifications => {
              // console.log('PUSHLOG: getInitialNotification', notifications);
              if (notifications) {
                notifications.data.forEach(notification => {
                  const notificationData = JSON.parse(notification.payload);
                  if (notification.opened) {
                    this.onNotificationOpened(notificationData);
                  } else {
                    this.handlePushData(notificationData);
                  }
                });
              }
            });
            // .catch(err => console.error('getInitialNotifiation() failed', err));
          }
          break;
        default:
github demokratie-live / democracy-client / src / hocs / PushNotifications.js View on Github external
LISTENERS_ADDED = true;
            NotificationsAndroid.setRegistrationTokenUpdateListener(async deviceToken => {
              // console.log('PUSHLOG: setRegistrationTokenUpdateListener', deviceToken);
              // TODO: Send the token to my server so it could send back push notifications...
              const tokenSucceeded = await client.mutate({
                mutation: ADD_TOKEN,
                variables: {
                  token: deviceToken,
                  os: 'android',
                },
              });
              if (tokenSucceeded) {
                await AsyncStorage.setItem('push-token', deviceToken);
              }
            });
            NotificationsAndroid.refreshToken();

            // On Android, we allow for only one (global) listener per each event type.
            NotificationsAndroid.setNotificationReceivedListener(notification => {
              // console.log('PUSHLOG: setNotificationReceivedListener', notification);
              const notificationData = JSON.parse(notification.getData().payload);
              this.onNotificationReceivedForeground(notificationData);
            });
            NotificationsAndroid.setNotificationOpenedListener(notification => {
              // console.log('PUSHLOG: setNotificationOpenedListener', notification);
              const notificationData = JSON.parse(notification.getData().payload);
              this.onNotificationOpened(notificationData);
            });

            PendingNotifications.getInitialNotification().then(notifications => {
              // console.log('PUSHLOG: getInitialNotification', notifications);
              if (notifications) {
github demokratie-live / democracy-client / src / hocs / PushNotifications.js View on Github external
componentDidMount() {
      switch (Platform.OS) {
        case 'ios':
          // console.log('PUSHLOG: NotificationsIOS.consumeBackgroundQueue();');
          NotificationsIOS.consumeBackgroundQueue();
          break;

        default:
          break;
      }
    }
github demokratie-live / democracy-client / src / hocs / PushNotifications.js View on Github external
// TODO: Send the token to my server so it could send back push notifications...
              const tokenSucceeded = await client.mutate({
                mutation: ADD_TOKEN,
                variables: {
                  token: deviceToken,
                  os: 'android',
                },
              });
              if (tokenSucceeded) {
                await AsyncStorage.setItem('push-token', deviceToken);
              }
            });
            NotificationsAndroid.refreshToken();

            // On Android, we allow for only one (global) listener per each event type.
            NotificationsAndroid.setNotificationReceivedListener(notification => {
              // console.log('PUSHLOG: setNotificationReceivedListener', notification);
              const notificationData = JSON.parse(notification.getData().payload);
              this.onNotificationReceivedForeground(notificationData);
            });
            NotificationsAndroid.setNotificationOpenedListener(notification => {
              // console.log('PUSHLOG: setNotificationOpenedListener', notification);
              const notificationData = JSON.parse(notification.getData().payload);
              this.onNotificationOpened(notificationData);
            });

            PendingNotifications.getInitialNotification().then(notifications => {
              // console.log('PUSHLOG: getInitialNotification', notifications);
              if (notifications) {
                notifications.data.forEach(notification => {
                  const notificationData = JSON.parse(notification.payload);
                  if (notification.opened) {
github JetBrains / youtrack-mobile / src / components / push-notifications / push-notifications.ios.js View on Github external
/* @flow */
import NotificationsIOS from 'react-native-notifications';

import appPackage from '../../../package.json'; // eslint-disable-line import/extensions
import Router from '../router/router';
import log from '../log/log';
import type Api from '../api/api';

const {KONNECTOR_URL} = appPackage.config;

let appleDeviceToken = null;

NotificationsIOS.addEventListener('remoteNotificationsRegistered', deviceToken => {
  log.info(`Apple device token received: "${deviceToken}"`);
  appleDeviceToken = deviceToken;
});

NotificationsIOS.addEventListener('notificationReceivedBackground', notification => {
  log.info('PUSH:notification received in background', notification);
});
NotificationsIOS.addEventListener('notificationReceivedForeground', notification => {
  log.info('PUSH:notification received in foreground', notification);
});

NotificationsIOS.addEventListener('notificationOpened', notification => {
  const {ytIssueId, ytUserId} = notification.getData();
  log.info(`PUSH:notification opened for issue "${ytIssueId}" for user "${ytUserId}"`);
  if (!ytIssueId) {
    return;
github demokratie-live / democracy-client / src / hocs / PushNotifications.js View on Github external
componentWillUnmount() {
      switch (Platform.OS) {
        case 'ios':
          // prevent memory leaks!
          NotificationsIOS.removeEventListener(
            'remoteNotificationsRegistered',
            this.onPushRegistered,
          );
          NotificationsIOS.removeEventListener(
            'remoteNotificationsRegistrationFailed',
            this.onPushRegistrationFailed,
          );
          NotificationsIOS.removeEventListener(
            'notificationReceivedForeground',
            this.onNotificationReceivedForeground,
          );
          NotificationsIOS.removeEventListener(
            'notificationReceivedBackground',
            this.onNotificationReceivedBackground,
          );
          NotificationsIOS.removeEventListener('notificationOpened', this.onNotificationOpened);
          break;

        default:
          break;
      }
    }

react-native-notifications

Advanced Push Notifications (Silent, interactive notifications) for iOS & Android

MIT
Latest version published 1 year ago

Package Health Score

65 / 100
Full package analysis