How to use the @react-native-community/push-notification-ios.addEventListener function in @react-native-community/push-notification-ios

To help you get started, we’ve selected a few @react-native-community/push-notification-ios 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 OriginProtocol / origin / mobile / src / PushNotifications.js View on Github external
async componentDidMount() {
    // Add an event listener to log registration errors in development
    if (__DEV__) {
      PushNotificationIOS.addEventListener('registrationError', error =>
        console.warn(error)
      )
    }

    PushNotification.configure({
      // Called when Token is generated (iOS and Android) (optional)
      onRegister: deviceToken => {
        // Save the device token into redux for later use with other accounts
        this.props.setDeviceToken(deviceToken['token'])
      },
      // Called when a remote or local notification is opened or received
      onNotification: notification => {
        this.onNotification(notification)
        // https://facebook.github.io/react-native/docs/pushnotificationios.html
        if (Platform.OS === 'ios') {
          notification.finish(PushNotificationIOS.FetchResult.NoData)
github OriginProtocol / origin / mobile / src / PushNotifications.js View on Github external
// completely closed
      PushNotificationIOS.getInitialNotification().then(notification => {
        if (notification) {
          // backgroundNotification is an instance of PushNotificationIOS, create
          // a notification object from it
          const notificationObj = {
            alert: this.state.backgroundNotification.getAlert(),
            data: this.state.backgroundNotification.getData()
          }
          // Pop the alert with option to redirect to WebView
          this.onNotification(notificationObj)
        }
      })

      // Get notifications that were triggered when the app was backgrounded
      PushNotificationIOS.addEventListener('notification', notification => {
        if (AppState.currentState === 'background') {
          // Save notification to state so it can be dealt with when the user
          // foregrounds the app
          console.debug('Setting background notification')
          this.setState({ backgroundNotification: notification })
        }
      })

      AppState.addEventListener('change', newState => {
        if (
          newState === 'active' &&
          this.state.backgroundNotification !== null
        ) {
          // backgroundNotification is an instance of PushNotificationIOS, create
          // a notification object from it
          const notification = {
github aws-amplify / amplify-js / packages / pushnotification / src / PushNotification.ts View on Github external
addEventListenerForIOS(event, handler) {
		const that = this;
		if (event === REMOTE_TOKEN_RECEIVED) {
			PushNotificationIOS.addEventListener('register', data => {
				handler(data);
			});
		}
		if (event === REMOTE_NOTIFICATION_RECEIVED) {
			PushNotificationIOS.addEventListener('notification', handler);
		}
	}
github aws-amplify / amplify-js / packages / pushnotification / src / PushNotification.ts View on Github external
addEventListenerForIOS(event, handler) {
		const that = this;
		if (event === REMOTE_TOKEN_RECEIVED) {
			PushNotificationIOS.addEventListener('register', data => {
				handler(data);
			});
		}
		if (event === REMOTE_NOTIFICATION_RECEIVED) {
			PushNotificationIOS.addEventListener('notification', handler);
		}
	}