SDK Callbacks

We recommend putting all SDK callbacks within your application's main onCreate method to ensure proper handling of all events.

SDK Lifecycle Callbacks

These callbacks can be implemented to observe SDK loading and exiting.

In order to implement these callbacks you must have a class that calls the SDK's registerSDKLifecycleCallbacks method and implements the callback(s) within it.

PushSDK.registerPushSDKLifecycleCallbacks(object : PNPushSDKLifecycleCallbacks {
    // Add function overrides here
})

The following SDK Lifecycle callbacks are available:

Finished Loading

This callback is executed when the SDK finishes its initialization and is ready for interaction.

override fun onPushSDKDidFinishLoading(configuration: PNApplicationConfig, subscriberStatus: PNSubscriberStatus) {
    // Add code to execute after SDK finishes loading
}

Permission Lifecycle Callbacks

These callbacks can be implemented to observe to a user's permission authorization changes.

In order to implement these callbacks you must have a class that calls the SDK's registerPermissionLifecycleCallbacks method and implements the callback(s) within it.

PushSDK.registerPermissionLifecycleCallbacks(object : PNPermissionLifecycleCallbacks {
    // Add function overrides here
})

The following Permission Lifecycle callbacks are available:

Permission Status Changed

This callback is executed when a user's permission status/authorization has changed.

The response variable represents the user's new permission status.

override fun onPushSDKDidReceivePermissionResponse(response: PNPermissionResponse) {
    // Add code to execute after a user's notification permission has changed
}

Notification Lifecycle Callbacks

These callbacks can be implemented to observe events like impressions, opens, and other interactions with notifications.

In order to implement these callbacks you must have a class that calls the SDK's registerNotificationLifecycleCallbacks method and implements the callback(s) within it.

PushSDK.registerNotificationLifecycleCallbacks(object : PNNotificationLifecycleCallbacks {
    // Add function overrides here
})

The following Notification Lifecycle callbacks are available:

Notification Received

This callback is executed when a user receives a notification

override fun onPushSDKDidReceiveRemoteNotification(notification: PNNotification) {
    // Add code to execute after the subscriber's device receives a notification
}

Notification Opened With URI/URL Destination

This callback is executed when a notification is opened that has a landing URL attached. The subscriber should be navigated to the view that represents the URL.

This method expects a Boolean response. If the response is true then the SDK will perform no additional actions for this notification open. If the response is false then the SDK will attempt to navigate the subscriber to the destination URL.

override fun onPushSDKDidReceiveNotificationDestination(destination: String, interaction: PNNotificationInteraction): Boolean {
    // Navigate to a activity within your application using the destination (the Landing URL)

    // Return true to inform the SDK that it should not navigate
    return true
}

See the Deep Linking documentation for a complete example.

App Message Lifecycle Callbacks

These callbacks can be implemented to observe events like impressions, opens, and other interactions with app messages.

In order to implement these callbacks you must have a class that calls the SDK's registerAppMessageLifecycleCallbacks method and implements the callback(s) within it.

PushSDK.registerAppMessageLifecycleCallbacks(object : PNAppMessageLifecycleCallbacks {
    // Add function overrides here
})

The following App Message Lifecycle callbacks are available:

App Message Will Present

This callback is executed when an App Message is presented to a user.

override fun onPushSDKWillPresentAppMessage(appMessage: PNAppMessage) {
    // Add code to execute when a user's device presents an app message
}

App Message Received User Interaction

This callback is executed when a user interacts with an App Message.

This method expects a Boolean response. If the response is true then the SDK will not handle the interaction or attempt to perform navigation when the interaction is an Open URL action. If the response is false then the SDK will process the interaction and if the interaction is an Open URL action will attempt to navigate the user to the destination URL by using the open method.

override fun onPushSDKDidReceiveAppMessageInteraction(interaction: PNAppMessageInteraction, appMessage: PNAppMessage): Boolean {
    // Add code to execute when a user interacts with an app message
    
    // Return true to inform the SDK that it should not handle the interaction
    return true
}

Last updated