Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

What Callback to run any statement when notification is show in iOS #2411

Open
muslimmuda15 opened this issue May 15, 2024 · 0 comments
Open

Comments

@muslimmuda15
Copy link

I try to implementation like this:

class NotifHandler {
  onNotification(notification) {
    console.log('onNotifHandler:', notification);

    if (typeof this._onNotification === 'function') {
      this._onNotification(notification);
    }
  }

  onRegister(token) {
    // console.log('NotifHandler:', token);

    if (typeof this._onRegister === 'function') {
      this._onRegister(token);
    }
  }

  onRemoteFetch(notificationData) {
    console.log('onRemoteFetchNotifHandler:', notificationData);
  }

  attachRegister(handler) {
    this._onRegister = handler;
  }

  attachNotification(handler) {
    this._onNotification = handler;
  }
}

const handler = new NotifHandler();

PushNotification.configure({
  // (optional) Called when Token is generated (iOS and Android)
  onRegister: handler.onRegister.bind(handler),

  // (required) Called when a remote or local notification is opened or received
  onNotification: handler.onNotification.bind(handler),

  // IOS ONLY (optional): default: all - Permissions to register.
  permissions: {
    alert: true,
    badge: true,
    sound: true,
  },

  // Should the initial notification be popped automatically
  // default: true
  popInitialNotification: true,

  /**
   * (optional) default: true
   * - Specified if permissions (ios) and token (android and ios) will requested or not,
   * - if not, you must call PushNotificationsHandler.requestPermissions() later
   */
  requestPermissions: true,
});
PushNotification.localNotificationSchedule({
    date: new Date(Date.now() + 10 * 1000),
    title: "Title",
    message: "Message",
    playSound: true,
    number: 10,
    soundName: 'default'
})

But after 10 seconds notification is work well, but onNotification seems not working when notification is showing.
How to get callback notification when showing, not by tapping?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant