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

 

 

 

Update your info.plist

1. Return to your project in Xcode. In your Info.plist file add "XtremePushApplicationKey" in key field and your application key in value field. You can find the "XtremePushApplicationKey" in the Settings (General Settings) page of your app under 'App Key' as seen above.

 

 

2.  If you plan to use Location Services, make sure to include the entry NSLocationAlwaysUsageDescription in your Info.plist file if you have not already done so. Enter an appropriate value exchange message for why your app uses location services.  

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 enable XtremePush Notifications you must modify your application delegate. This guide is for Objective-C if you are using Swift see the Swift Guide. Follow these three steps to complete the integration process:

1. In your Application Delegate, import XPush:

#import "XPush.h"

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

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customisation after application launch.

// Setup xtremepush
NSInteger types;

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

[XPush registerForRemoteNotificationTypes:types];
[XPush applicationDidFinishLaunchingWithOptions:launchOptions];

Development/Debug builds: 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. You can also turn on debug logs for the SDK in this way:


[XPush registerForRemoteNotificationTypes:types];
    // Only runs for development builds sets push to sandbox mode and turns on debug logs
    #if DEBUG
    [XPush setSandboxModeEnabled:YES];
    [XPush setShouldShowDebugLogs:YES];
    #endif
[XPush applicationDidFinishLaunchingWithOptions:launchOptions];

 

3. Finally add the the three 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 {
[XPush applicationDidReceiveRemoteNotification:userInfo];
}

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[XPush applicationDidReceiveLocalNotification:notification];
}

Retrieving your xtremepush ID

If your app is successfully registering with the platform you should be able to retrieve your XtremePush ID. This can be accomplished by calling the deviceInfo method:

+ (NSDictionary *)deviceInfo

This method returns a Dictionary that contains your devices id as obtained from XtremePush server. If your device has not received an id then it has not successfully registered and there is an issue with your integration. If for example you want to quickly output the the device id to the debug area in Xcode you would use it like this:

NSLog(@"XPush Device Info: %@", [XPush deviceInfo]);

And the output should appear as follows:

XPush Device Info: { XPushDeviceID = 1260296; }

If you successfully retrieve the ID it can be used to identify your device on the platform and to send a push notification to just that device.

Have more questions? Submit a request

0 Comments

Article is closed for comments.