Integrate your iOS App with the Platform (Swift3)

Create an App on the Platform

1. Add your App on the platform by clicking *"+ NEW APP"* on your XtremePush Dashboard at dashboard.xtremepush.com 

2. Enter the App Name, upload the App icon, and give a short description of the app. An App key and token have been automatically generated. The App key is used in your iOS project to connect the app and platform. The app token will only be used if you use the external API. Save your settings and copy the app key. Your saved settings should be similar to the following.

 

 

Upload Push Certs

Go to your app home and navigate to Settings > Application Keys. On the left hand side select the iOS App radio button and upload your app's iOS push notification certificates for development and production, and click save. If you certificates are password protected be sure to add the correct passwords when uploading them.

If you have not set up push notification certificates before this is covered in our article on APNs Certificates  

 

Initialise the SDK in your App delegate

To initialise XtremePush you must modify your Application Delegate. Inside application didFinishLaunchingWithOptions add the following code to set up XtremePush:

1. In your Application Delegate, import XPush:

import XPush

2. Inside applicationDidFinishLaunching:withOptions: add the following code to set up XtremePush:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {    
    XPush.setAppKey("APP_KEY_FROM_THE_DASHBOARD")
    XPush.applicationDidFinishLaunching(options: launchOptions)    
    return true
}

 

Adding Push Messaging Functionality

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

To add the Xtremepush notifications, you must add the XPush register function call to your didFinishLaunchingWithOptions method in your Application Delegate:

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 applicationDidFinishLaunching:withOptions: add the following code to set up XtremePush:

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

    XPush.register(forRemoteNotificationTypes: [.alert, .badge, .sound]);
    
    #if DEBUG
    XPush.setSandboxModeEnabled(true)
    #endif
    
    XPush.applicationDidFinishLaunching(options: launchOptions)
    return true
}

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)
}

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

func application(_ application: UIApplication, 
    didReceive notification: UILocalNotification) {

    XPush.applicationDidReceive(notification)
}

 

Add Interactive Notifications Support

If using interactive notifications you must also add these functions to you Application Delegate file.

func application(_ application: UIApplication,
    handleActionWithIdentifier identifier: String?,
    forRemoteNotification userInfo: [AnyHashable : Any],
    completionHandler: @escaping () -> Void) {
    
    XPush.application(application,
                      handleActionWithIdentifier: identifier,
                      forRemoteNotification: userInfo,
                      completionHandler: completionHandler)
}

func application(_ application: UIApplication,
    handleActionWithIdentifier identifier: String?,
    for notification: UILocalNotification, 
    completionHandler: @escaping () -> Void) {
    
    XPush.application(application,
                      handleActionWithIdentifier: identifier,
                      for: notification,
                      completionHandler: completionHandler)
}
Have more questions? Submit a request

0 Comments

Article is closed for comments.