Upgrade iOS SDK from v3

📘

This page is kept as an archive for iOS integrations migrating from v3. Review our iOS SDK guides for current integrations.

Recently we improved significantly the iOS SDK integration process. Although the new method of integration is much simpler, if you are currently using v3.x of the iOS SDK and want to update to v4, there are a few changes that you will have to make.

New XPush.framework

The changes you should make to your project are:

  • Remove the older XPush.h and XPush.a files from your project
  • Import the SDK to your iOS app. Follow steps indicated in our dedicated guide

Bridging header

If your app is a Swift app, please remove the #import "XPush.h" line from your bridging header.

You can now import XPush like any other Swift module.

UNUserNotificationCenter

In newer versions we tried to do as much notification set up work as possible on your behalf, so you can concentrate on your app. We implemented UNUserNotificationCenter's delegate so you are free to delete any UserNotification framework related code and we strongly recommend doing so. If you absolutely must keep it, make sure you are forwarding the UNNotificationCenter calls to XPush.

Universal Notification Options

NotificationTypes have been improved to work with a universal notification type (XPNotificationType) rather than different types for different versions.

Old way

var types: Int

if Float(UIDevice.current.systemVersion) ?? 0.0 >= 8.0 {
    types = [.badge, .alert, .sound].rawValue
} else {
    types = [.alert, .sound, .badge].rawValue
}

XPush.register(forRemoteNotificationTypes: types)
NSInteger types;

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.f) {
    types = UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound;
} else {
    types = UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeBadge;
}

[XPush registerForRemoteNotificationTypes:types];

New way

XPush.register(forRemoteNotificationTypes: [.alert, .sound, .badge])
[XPush registerForRemoteNotificationTypes:XPNotificationType_Alert | XPNotificationType_Sound | XPNotificationType_Badge];

Delegate Function Changes

A change has been made from using didRecieveRemoteNotification. You must change this function to the following:

Old way

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
        XPush.applicationDidReceiveRemoteNotification(userInfo)
}

New way

func application(_ application: UIApplication,
                     didReceiveRemoteNotification userInfo: [AnyHashable : Any],
                     fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
  XPush.applicationDidReceiveRemoteNotification(userInfo, fetchCompletionHandler: completionHandler)
}
- (void)application:(UIApplication *)application 
    didReceiveRemoteNotification:(NSDictionary *)userInfo 
    fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

    [XPush applicationDidReceiveRemoteNotification:userInfo
        fetchCompletionHandler:completionHandler];
    }

Custom message handling

In previous versions, custom message handling was possible with regards to notifications, but now it allows for all message types.

To changeover to the new functionality you should first remove any custom logic you added to the didReceiveRemoteNotification app.delegate function.

Now register the new callback like the following:

XPush.registerMessageResponseHandler { x in
            switch x.action.type {
                
            case .click:
                // Logic when message is clicked
                
            case .dismiss:
                // Logic when message is dismissed
                
            case .present:
                // Logic when message is received in foreground
                
            }
        }
[XPush registerMessageResponseHandler:^(XPMessageResponse *response) {
    switch (response.action.type) {
        case XPActionType_Click:
            // Logic when message is clicked
            break;
        case XPActionType_Dismiss:
            // Logic when message is dismissed
            break;
        case XPActionType_Present:
            // Logic when message is received in foreground
            break;
    }
}];

More details on this new callback can be found here.

Additional new features

Foreground notification handling

Additional control options have been implemented to allow for more customised behaviour when a push notification is received.  

More information on this feature can be found here.

Interactive notifications

Xtremepush customers now have the option of adding multiple buttons to interactive notifications. 

To set up your interactive notification campaign on the platform see our Push categories dedicated guide.

To see how you can handle the individual button clicks, see here.