Events

List of OneSignal Events

Notification

permissionChanged

This event is triggered when the user's notification permission status changes.

Handling The Event

Provide a callback to the addPermissionObserver function.

Notifications.addPermissionObserver(new NotificationPermissionObserver() {
  @Override
  void onNotificationPermissionChanged(boolean permission) {
    if (permission) {
      // User just accepted notifications or turned them back on! 🙂
    } else {
      // User just turned off notificaitons. 😢
    }
  }
});

// Android - Kotlin
class MyNotificationPermissionObserver : OSNotificationPermissionObserver {
  func onNotificationPermissionChanged(permission: Bool) {
    if (permission) {
      // User just accepted notifications or turned them back on! 🙂
    } else {
      // User just turned off notificaitons. 😢
    }
  }
}

let myObserver = MyNotificationPermissionObserver()
Notifications.addPermissionObserver(observer: myObserver)

OneSignal.addPermissionObserver(e => {
  if (e.permission) {
    // User just accepted notifications or turned them back on! 🙂
  } else {
    // User just turned off notificaitons. 😢
  }
});

Notifications.PermissionChanged += onNotificationPermissionChanged;
void onNotificationPermissionChanged(object sender, NotificationPermissionChangedEventArgs e)
{
  if (e.permission)
  {
    // User just accepted notifications or turned them back on! 🙂
  }
  else
  {
    // User just turned off notificaitons. 😢
  }
}

Event Properties

You may access the following properties on the permissionChanged event.

PropertyTypeDescription
permissionBoolIndicates whether the user opted into receiving notifications. Notifications will only be delivered if this property is true.

clicked

This event is triggered when the user taps on a notification.

Handling The Event

Provide a callback to the setClickListener function.

Notifications.addClickListener(new NotificationClickListener() {
   @Override
   void onClick(NotificationClickEvent e) {
     
   }
});

OneSignal.setClickListener(e => {
  // Handle notification click event here
});

Notifications.Clicked += onClick;
void onClick(object sender, NotificationClickEventArgs e)
{
  
}

Event Properties

You may access the following properties on the clicked event.

PropertyTypeDescription
clickTypeClickType
actionIdString
notificationNotification

willDisplay

This event is triggered right before a notification is presented to the user.

Handling The Event

Provide a callback to the setWillDisplayListener function.

OneSignal.setWillDisplayListener((event) => {
  // Handle notification will display event here
});

Event Properties

PropertyTypeDescription

In-App Message

clicked

This event is triggered when a user taps on an In-App Message.

Handling the event

Provide a callback to the setInAppMessageClickHandler function.

OneSignal.setInAppMessageClickHandler((event) => {
  // Handle in-app message click event here
});

Lifecycle events

  • willDisplay - Triggered right before a message is presented to the user.
  • didDisplay - Triggered right after a message is presented to the user.
  • willDismiss - Triggered right after a user dismisses an event and before the message is closed
  • didDidmiss - Triggered right after a message is closed

Handling lifecycle events

OneSignal.setInAppMessageLifecycleHandler({
  willDisplay: (event) => {
    // Handle in-app message will display event here
  },
  didDisplay: (event) => {
    // Handle in-app message did display event here
  },
  willDismiss: (event) => {
    // Handle in-app message will dismiss event here
  },
  didDismiss: (event) => {
    // Handle in-app message did dismiss event here
  }
});

Push Subscription