Skip to main content
The methods below require the OneSignal SDK versions 3 & 4.It is recommended to upgrade to our latest version 5 SDKs for User Model APIs.See Update to User Model for migration steps.

Foreground Notification Received Event

setNotificationWillShowInForegroundHandler Method

Runs before displaying a notification while the app is in focus. Use this handler to read notification data and change it or decide if the notification should show or not. Call setNotificationWillShowInForegroundHandler before you set OneSignal.setNotificationOpenedHandler. Note: this runs after the Notification Service Extension which can be used to modify the notification before showing it.

OSNotificationReceivedEvent methods:

Notification Opened Event

setNotificationOpenedHandler Method

This method takes a OSNotificationOpenedHandler callback that itself accepts a parameter result of type OSNotificationOpenedResult.
OSNotificationOpenResult fields:

OSNotification Class

The OSNotification class is composed of all getters. The class combines the original OSNotification with data previously on the OSNotificationPayload class into a single large OSNotification class. More details in OSNotification Payload.

OSNotificationAction Class

The action the user took on the notification. More details in OSNotification Payload.

Background Notification Received Event

Android Background Notification Received Event

Requires native code. See Android Notification Service Extension for more details.

iOS Background Notification Received Event

application(_:didReceiveRemoteNotification:fetchCompletionHandler:) method

Apple provides this method to indicate a notification was received when your app is running in the foreground or background. This method allows data to be fetched while the app is running in the background. See details and discussion for requirements in Apple’s Developer Documentation. If your app is force-quite, this method will not run and requires the Service Extensions for detection. You must have background mode enabled and send the push with content_available in the iOS Message Settings for method to be called while app is in background.