SDK Delegates

We recommend including all SDK delegates within your application's AppDelegate class to ensure proper handling of all events.

SDK Lifecycle Delegates

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

You must inform the SDK what class is going to implement this protocol. This can be done using the setSDKLifecycleDelegate method on the SDK:

PushSDK.setSDKLifecycleDelegate(self)

The following SDK Lifecycle delegates are available:

Finished Loading

This delegate is called when the SDK finishes its initialization and is ready for interaction.

func pushSDK(didFinishLoading configuration: PNApplicationConfig, withNotificationSettings settings: UNNotificationSettings) {
    // Add code to execute after SDK finishes loading
}

Permission Lifecycle Delegates

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

You must inform the SDK what class is going to implement this protocol. This can be done using the setPermissionLifecycleDelegate method on the SDK:

PushSDK.setPermissionLifecycleDelegate(self)

The following Permission Lifecycle delegates are available:

Permission Status Changed

This delegate is called when a user's permission status/authorization has changed.

The status variable represents the user's new permission status using the UNAuthorizationStatus enum.

func pushSDK(didReceivePermissionStatusChange status: UNAuthorizationStatus, withSettings settings: UNNotificationSettings) {
    // Add code to execute after a user's notification permission has changed
}

Notification Lifecycle Delegates

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

You must inform the SDK what class is going to implement this protocol. This can be done using the setNotificationLifecycleDelegate method on the SDK:

PushSDK.setNotificationLifecycleDelegate(self)

The following Notification Lifecycle delegates are available:

Notification Received

This delegate is called when a user receives a notification

func pushSDK(didReceiveNotification notification: PNNotification)
    // Add code to execute after the subscriber's device receives a notification
}

Notification Opened With URI/URL Destination

This delegate is called 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 navigation action for this notification open. If the response is false then the SDK will attempt to navigate the subscriber to the destination URL by using the open method.

func pushSDK(didReceiveNotificationDestination destination: String, withInteraction interaction: PNNotificationInteraction) -> Bool {
    // Navigate to a view 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 Delegates

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

You must inform the SDK what class is going to implement this protocol. This can be done using the setAppMessageLifecycleDelegate method on the SDK:

PushSDK.setAppMessageLifecycleDelegate(self)

The following App Message Lifecycle delegates are available:

App Message Will Present

This delegate is called when an App Message is presented to a user.

func pushSDK(willPresentAppMessage appMessage: PNAppMessage) {
    // Add code to execute when a user's device presents an app message
}

App Message Received User Interaction

This delegate is called 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.

func pushSDK(didReceiveAppMessageInteraction interaction: PNAppMessageInteraction, fromAppMessage appMessage: PNAppMessage) -> Bool {
    // 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