Integrate your iOS App with the Platform (Objective-C)

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/XPush.h>

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

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [XPush setAppKey: @"APP_KEY_FROM_THE_DASHBOARD"];
    [XPush applicationDidFinishLaunchingWithOptions:launchOptions];
}

 

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:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [XPush setAppKey: @"APP_KEY_FROM_THE_DASHBOARD"];

    [XPush registerForRemoteNotificationTypes:XPNotificationType_Alert | 
    XPNotificationType_Sound | XPNotificationType_Badge];

    #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.

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {

    [XPush applicationDidRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

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

    [XPush applicationDidFailToRegisterForRemoteNotificationsWithError:error];
}

- (void)application:(UIApplication *)application 
    didReceiveRemoteNotification:(NSDictionary *)userInfo 
    fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {

    [XPush applicationDidReceiveRemoteNotification:userInfo
        fetchCompletionHandler:completionHandler];
} 

- (void)application:(UIApplication *)application 
    didReceiveLocalNotification:(UILocalNotification *)notification {

    [XPush applicationDidReceiveLocalNotification:notification];
}

 

Add Interactive Notifications Support

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

- (void) application:(UIApplication *)application 
    handleActionWithIdentifier:(NSString *)identifier 
    forRemoteNotification:(NSDictionary *)userInfo
    completionHandler:(void (^)())completionHandler {

    [XPush application:application
           handleActionWithIdentifier:identifier
           forRemoteNotification:userInfo
           completionHandler:completionHandler];
}

- (void) application:(UIApplication *)application 
    handleActionWithIdentifier:(NSString *)identifier 
    forLocalNotification:(UILocalNotification *)notification
    completionHandler:(void (^)())completionHandler {

    [XPush application:application
           handleActionWithIdentifier:identifier
           forLocalNotification:notification
           completionHandler:completionHandler];
}
Have more questions? Submit a request

0 Comments

Article is closed for comments.