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

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 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
constructor(props) {
      super(props);
      switch (Platform.OS) {
        case 'ios':
          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());
          });
github demokratie-live / democracy-client / src / hocs / PushNotifications.js View on Github external
constructor(props) {
      super(props);
      switch (Platform.OS) {
        case 'ios':
          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());
github zulip / zulip-mobile / src / notification / index.js View on Github external
listen(name: string, handler: (...empty) => void | Promise) {
    if (Platform.OS === 'ios') {
      NotificationsIOS.addEventListener(name, handler);
      this.unsubs.push(() => NotificationsIOS.removeEventListener(name, handler));
    }
    const subscription = DeviceEventEmitter.addListener(name, handler);
    this.unsubs.push(() => subscription.remove());
  }
github RocketChat / Rocket.Chat.ReactNative / app / notifications / push / push.ios.js View on Github external
constructor() {
		this.onRegister = null;
		this.onNotification = null;
		this.deviceToken = null;

		NotificationsIOS.addEventListener('remoteNotificationsRegistered', (deviceToken) => {
			this.deviceToken = deviceToken;
		});

		NotificationsIOS.addEventListener('notificationOpened', (notification, completion) => {
			const { background } = reduxStore.getState().app;
			if (background) {
				this.onNotification(notification);
			}
			completion();
		});

		const actions = [];
		actions.push(new NotificationCategory({
			identifier: 'MESSAGE',
			actions: [replyAction]
		}));
github JetBrains / youtrack-mobile / src / components / push-notifications / push-notifications.ios.js View on Github external
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;
  }

  Router.SingleIssue({issueId: ytIssueId});
});

export function registerForPush(api: Api): Promise {
  return new Promise(async (resolve, reject) => {
    /**
github mattermost / mattermost-mobile / app / push_notifications / push_notifications.ios.js View on Github external
constructor() {
        this.deviceNotification = null;
        this.onRegister = null;
        this.onNotification = null;
        this.onReply = null;
        this.reduxStore = null;

        NotificationsIOS.addEventListener(DEVICE_REMOTE_NOTIFICATIONS_REGISTERED_EVENT, this.onRemoteNotificationsRegistered);
        NotificationsIOS.addEventListener(DEVICE_NOTIFICATION_RECEIVED_FOREGROUND_EVENT, this.onNotificationReceivedForeground);
        NotificationsIOS.addEventListener(DEVICE_NOTIFICATION_OPENED_EVENT, this.onNotificationOpened);
    }

react-native-notifications

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

MIT
Latest version published 8 months ago

Package Health Score

72 / 100
Full package analysis