iOS push notifications

Configure push notifications within Xtremepush and your app

Push notifications for iOS require certificates generated from your Apple Developer account. Follow these steps to enable push notifications:

Get Apple certificates

  1. Log in to your Apple Developer account at (https://developer.apple.com/membercenter/)
  2. Select Certificates, IDs and Profiles
  3. Select Identifiers
196
  1. Select the app you are integrating with Xtremepush and click Edit.
  2. In iOS App ID Settings, click Edit next to Push Notifications.
805
  1. Under Development SSL Certificate click "Create Certificate" and follow the step-by-step instructions to generate and download the certificate.
679
  1. Repeat this procedure to generate and download a certificate under "Production SSL Certificate".
  2. Open the certificates, which will show them in the Keychain Access application.
  3. Select the certification and expand it to see the key below it.
  4. Hold ⌘Cmd to select both the certificate and key and export them using File > Export Items..., choosing the (.p12) format.

Configure Xtremepush

  1. In Xtremepush, navigate to **Settings > Apps & sites > click on the matching iOS app > Push > Push Settings.
  2. Upload the Production and Sandbox (development) certificates and press Save.

Add to app

For basic testing, you can add the SDK's push notification register function to your didFinishLaunchingWithOptions method in your Application Delegate. For better user experience, the registration for push notifications should only be triggered after a prompt or value-exchange in your app, so your users know why push permissions are being requested and are more likely to agree to opt in. Learn more in our dedicated guide here.

🚧

Xtremepush does not require you to set Delegate of UNUserNotificationCenter as it will conflict with our library.

If you test using development builds then you should turn on Sandbox Mode as Apple uses a different gateway for builds compiled with a development mobile provisioning profile. If you only do enterprise builds you won't need this. Set sandbox mode in a statement that will only run for development builds as it should not be turned on in production.

Inside didFinishLaunchingWithOptions add the following:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    XPush.setAppKey("XPUSH_APP_KEY")

    // Add registration for push notifications
    XPush.register(forRemoteNotificationTypes: [.alert, .badge, .sound]);
    
    // Set push notification sandbox mode only for development builds
    #if DEBUG
    XPush.setSandboxModeEnabled(true)
    #endif
    
    XPush.applicationDidFinishLaunching(options: launchOptions)
    return true
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [XPush setAppKey: @"XPUSH_APP_KEY"];

    // Add registration for push notifications
    [XPush registerForRemoteNotificationTypes:XPNotificationType_Alert | 
    XPNotificationType_Sound | XPNotificationType_Badge];

    // Set push notification sandbox mode only for development builds
    #if DEBUG     
    [XPush setSandboxModeEnabled:YES];     
    #endif 

    [XPush applicationDidFinishLaunchingWithOptions:launchOptions];
}

Add the the following iOS remote notifications handling methods in Application delegate, and place the corresponding Xtremepush method call in each of these as shown.

func application(_ application: UIApplication, 
    didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data){

    XPush.applicationDidRegisterForRemoteNotifications(withDeviceToken: deviceToken as Data!)
}

func application(_ application: UIApplication,
    didFailToRegisterForRemoteNotificationsWithError error: NSError) {

    XPush.applicationDidFailToRegisterForRemoteNotificationsWithError(error)
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

    [XPush applicationDidRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {

    [XPush applicationDidFailToRegisterForRemoteNotificationsWithError:error];
}

Using UNUserNotificationCenterDelegate with the XPush iOS SDK

Why this matters:

The XPush SDK relies on UNUserNotificationCenterDelegate callbacks to:

  • track push opens/clicks
  • handle foreground presentation behaviour
  • process XPush-specific notification actions
❗️

Important:

iOS only allows one UNUserNotificationCenter delegate. If your app sets its own delegate, XPush will no longer receive these callbacks unless you forward them.

Recommended approach:

If you need a custom delegate (e.g., to handle another push provider), you can still do so — just forward XPush notifications to the SDK.

  1. Set the delegate Set your delegate once during app startup:
 [UNUserNotificationCenter currentNotificationCenter].delegate = self;
UNUserNotificationCenter.current().delegate
  1. Forward notifications to XPush in the delegate methods
#import <UserNotifications/UserNotifications.h>
#import <XPush/XPush.h>

@interface YourNotificationHandlerClass () <UNUserNotificationCenterDelegate>
@end

@implementation YourNotificationHandlerClass

#pragma mark - UNUserNotificationCenterDelegate

// Called when a notification is received while the app is in the foreground
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
       willPresentNotification:(UNNotification *)notification
         withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {

    NSDictionary *userInfo = notification.request.content.userInfo;

    if (userInfo[@"xpush"] != nil) {
        // Forward XPush notifications to the SDK
        [XPush userNotificationCenter:center
              willPresentNotification:notification
                withCompletionHandler:completionHandler];
        return; // SDK calls completionHandler
    }

    // Handle non-XPush notifications here (if applicable)
    completionHandler(UNNotificationPresentationOptionAlert);
}


// Called when the user taps a notification or interacts with an action button
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
         withCompletionHandler:(void (^)(void))completionHandler {

    NSDictionary *userInfo = response.notification.request.content.userInfo;

    if (userInfo[@"xpush"] != nil) {
        // Forward XPush notifications to the SDK
        [XPush userNotificationCenter:center
     didReceiveNotificationResponse:response
              withCompletionHandler:completionHandler];
        return; // SDK calls completionHandler
    }

    // Handle non-XPush notification actions here (if applicable)
    completionHandler();
}

@end
#import <UserNotifications/UserNotifications.h>
#import <XPush/XPush.h>

@interface YourNotificationHandlerClass () <UNUserNotificationCenterDelegate>
@end

@implementation YourNotificationHandlerClass

#pragma mark - UNUserNotificationCenterDelegate

// Called when a notification is received while the app is in the foreground
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
       willPresentNotification:(UNNotification *)notification
         withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {

    NSDictionary *userInfo = notification.request.content.userInfo;

    if (userInfo[@"xpush"] != nil) {
        // Forward XPush notifications to the SDK
        [XPush userNotificationCenter:center
              willPresentNotification:notification
                withCompletionHandler:completionHandler];
        return; // SDK calls completionHandler
    }

    // Handle non-XPush notifications here (if applicable)
    completionHandler(UNNotificationPresentationOptionAlert);
}


// Called when the user taps a notification or interacts with an action button
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
         withCompletionHandler:(void (^)(void))completionHandler {

    NSDictionary *userInfo = response.notification.request.content.userInfo;

    if (userInfo[@"xpush"] != nil) {
        // Forward XPush notifications to the SDK
        [XPush userNotificationCenter:center
     didReceiveNotificationResponse:response
              withCompletionHandler:completionHandler];
        return; // SDK calls completionHandler
    }

    // Handle non-XPush notification actions here (if applicable)
    completionHandler();
}

@end

Notes:

  • We check userInfo[@"xpush"] to route only XPush notifications to the SDK.
  • Return immediately after calling XPush so you don't accidentally call completionHandler twice.
  • If you support other providers, handle those in the else path.