Overview of how the SDK handles deep links and how to perform custom navigation within your application
The PushSDK handles opening of a notification in the following ways:
By default, the SDK will automatically call the open method using the landing URL attached to the notification.
If you implement the didReceiveNotificationDestination lifecycle delegate you can perform any custom logic needed when the notification is opened.
Implementing URL Handling Delegates
The PushSDK provides delegates that will be called when a subscriber interacts with a notification. These delegates should be implemented so that the subscriber is automatically navigated to the proper controller, page, or other view after opening the notification.
It is recommend to put all SDK delegates within your application's AppDelegate class to ensure proper handling of all notification events.
When the SDK receives a notification open event it will attempt to call one of the below delegates with parameters that you can use to navigate the subscriber to the appropriate view within your app. In order to implement these delegates you must have a class that implements PNNotificationLifecycleDelegate.
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)
[PushSDK setNotificationLifecycleDelegate:self];
For example, if a landing URL was provided within the notification and you implemented the delegate to handle subscriber navigation within your AppDelegate the code may look like this:
importPushly@mainclassAppDelegate:UIResponder, UIApplicationDelegate, PNNotificationLifecycleDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
PushSDK.setConfiguration(appKey:"YOUR_APP_KEY", withLaunchOptions: launchOptions) PushSDK.PushNotifications.showPermissionPrompt() { granted, settings, error in// optional callbackprint("User accepted permissions: \(granted)") } PushSDK.setNotificationLifecycleDelegate(self)returntrue } 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 navigatereturntrue }}
@import Pushly;
@interface AppDelegate () <PNNotificationLifecycleDelegate>
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
PushSDK.logLevel = PNLogLevelInfo;
[PushSDK setConfigurationAppKey:@"YOUR_APP_KEY" withLaunchOptions:launchOptions];
[PushSDKPushNotificationsSDK showPermissionPrompt:^(BOOL granted, UNNotificationSettings * _Nonnull settings, NSError * _Nullable error) {
NSLog(@"User accepted permissions: %d", granted);
}];
[PushSDK setNotificationLifecycleDelegate:self];
return YES;
}
- (BOOL)pushSDKDidReceiveNotificationDestination:(NSString *)destination withInteraction:(PNNotificationInteraction *)interaction {
// Navigate to a view within your application using the destination (the Landing URL)
// Return YES to inform the SDK that it should not navigate
return YES;
}
Notification Interaction Delegates
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 navigatereturntrue}
- (BOOL)pushSDKDidReceiveNotificationDestination:(NSString *)destination withInteraction:(PNNotificationInteraction *)interaction {
// Redirect to a view within your application using the destination (the Landing URL)
// Return YES to inform the SDK that it should not redirect
return YES;
}