LogoLogo
  • Home
  • Integration & SDKs
    • Web / Browser Push
      • Wordpress Integration Steps
      • Wix Integration Steps
      • Safari
        • Safari on Desktop
        • Safari on Mobile (iOS / iPadOS)
      • SDK
        • SDK Methods
        • SDK Events
        • Customizing Prompt CSS
        • AMP Support
        • E-Commerce / Abandoned Cart
    • Native App Push
      • Apple / iOS
        • P8 Key or P12 Cert Setup
        • SDK: Swift / Obj-C
          • Activity Tracking
          • Deep Linking
          • Live Activities
          • App Messages
          • Identity Synchronization
          • SDK Methods
          • SDK Delegates
        • SDK: React Native
        • SDK: Flutter
        • Advanced
          • Self-Managed Integration
        • iOS SDK Changelog
      • Android
        • Firebase App Setup
        • SDK: Kotlin / Java
          • Deep Linking
          • Activity Tracking
          • App Messages
          • Identity Synchronization
          • SDK Methods
          • SDK Callbacks
          • Live Activities
        • SDK: React Native
        • SDK: Flutter
        • Advanced
          • Self-Managed Integration
        • Android SDK Changelog
      • React Native
        • Android: Firebase App Setup
        • iOS: P8 Key or P12 Cert Setup
        • SDK: React Native
          • Deep Linking
          • Activity Tracking
          • Subscriber Matching
          • Live Activities
          • App Messages
          • SDK Methods
      • Flutter
        • Android: Firebase App Setup
        • iOS: P8 Key or P12 Cert Setup
        • SDK: Flutter
          • Deep Linking
          • Activity Tracking
          • Subscriber Matching
          • Live Activities
          • App Messages
          • SDK Methods
  • API
    • API Access Management
    • API Reference
  • Platform
    • Dashboard
    • Notifications
      • A/B Testing
      • Custom Buttons
      • Notification Previews
      • Inline Segmentation
      • Notification Templates
      • Macros
      • Native App Push Notifications
    • App Messages
    • Segments
      • Custom Geo Segmentation
    • Campaigns
    • Insights
    • User Management
    • Organizations
      • Multi-Factor Authentication
      • Single Sign On
        • Google Workspace
        • Microsoft Azure AD
        • Okta Workforce
      • Multi-Domain Notifications
      • Multi-Domain Segments
      • API Access
    • Multi-Channel Notifications
  • Info Center
    • Launch Guide & Best Practices
      • Landing Domain Whitelist
    • Web / Browser Push
      • Common Questions
      • Browser Support
      • Retrieve Push User ID
      • Not Getting Prompted
      • Not Receiving Notifications
      • How to Unsubscribe
    • Native App Push
      • Retrieve Push User ID
    • Workflow Planning
Powered by GitBook
On this page
  • Implementing URL Handling Delegates
  • Notification Interaction Delegates
  • Notification Opened With URI/URL Destination
  1. Integration & SDKs
  2. Native App Push
  3. Apple / iOS
  4. SDK: Swift / Obj-C

Deep Linking

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:

import Pushly

@main
class AppDelegate: 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 callback
            print("User accepted permissions: \(granted)")
        }
        PushSDK.setNotificationLifecycleDelegate(self)

        return true
    }

    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
    }
}
@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 navigate
    return true
}
- (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;
}

x

PreviousActivity TrackingNextLive Activities

Last updated 1 year ago