Thousands of businesses rely on Hipmob to keep their customers happy. See some here.

iOS Push Notifications with Hipmob


Overview

Hipmob provides hosted live chat for mobile applications. You sign up with us, we give you a code, you download our library, you integrate it into your app, and you can then talk to your users, figure out what they want and what problems they are having, and make them happy. No servers, no extra steps or code to write, wherever the users are, you get to focus on what you do well. This document covers integration of iOS push notifications with the Hipmob platform.
Hipmob can be configured to send push notifications to the user's iOS device whenever a message is sent to them while they are offline. This simplifies the developer's work: using a few configuration settings in the Hipmob management interface and by adding a few lines of configuration and code to their iOS app Hipmob will prompt the user to launch their app whenever any message is received for a user (either a support message or direct message from another user of their app). Hipmob's push notification integration uses Apple Push Notification Service (APNS): below we walk through configuring APNS, passing the APNS certificate to the Hipmob communication network and then configuring your application to receive APNS messages.

Setup

Visit the Local and Push Notification Programming Guide for the best instructions on how to setup and provision an Apple Push Notification certificate. To get started, visit the Apple Developer Member Center and open the iOS Provisioning Portal.

Figure 1: Apple Developer Member Center

Click on the App IDs option on the left to open the App IDs screen as shown in Figure 2 below.

Figure 2: App IDs

Find your application in the list, and then ensure that the Push Notification is enabled for both Development and Production, as shown in Figure 3 below. If you need to activate it for the first time, click Configure.

Figure 3: Configure Push Notification Support

Once done, click on the Configure button next to the App ID and then use the Download button to save the appropriate certificate as shown in Figure 4 below.
IMPORTANT Make sure you download the right certificate: for ad-hoc distribution (such as with TestFlight or HockeyApp) you will need a production certificate.

Figure 4: Download Certificates

Open the certificate on the computer: this will open up Keychain Access as shown in Figure 5 below.
IMPORTANT Make sure you open the My Certificates section in KeyChain Access: this ensures you will have the correct export options available.

Figure 5: Certificate in Keychain Access

Double click on the certificate and select Export as shown in Figure 6 below.

Figure 6: export the certificate

Make sure you export the certificate as a Personal Information Exchange (.p12) as shown in Figure 7 below.

Figure 7: exporting the certificate as a .p12

IMPORTANT Make sure you do NOT enter a password in the step shown in Figure 8 below.

Figure 8: save certificate with no password

Enabling Push

Log into your Hipmob account and go to the Apps page (at https://manage.hipmob.com/#apps). Click the Settings button.

Figure 9: application Settings

Select the Push Notifications option.

Figure 10: Push Notifications settings screen

Select the push certificate file, enable iOS push notifications and indicate if the certificate is a debug certificate or not as shown in Figure 11.

Figure 11: iOS push notification setup

And the Hipmob setup is complete. For security reasons the file can not be downloaded. If a certificate file has been uploaded, the Clear button will be displayed.

Figure 12: push notifications successfully setup

Code

In your app's main delegate, register for push notifications.
		    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ...
    // and, push notification registration and setup
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert)];
    
    ...
}
		  
Register for the token notification: you'll need to save the token NSData that is passed. In the example below, we save it to an attribute of the delegate.
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)tokenValue {
  self.token = [NSData dataWithData:tokenValue];
}
		  
Finally, when you open a chat session, pass the token:
HMChatViewController * livechat = [[HMChatViewController alloc] initWithAppID:appid andUser:nil];  
...
AppDelegate * app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    if(app.token != nil){
        // send it
        [livechat.chatView setPushToken:app.token];
    }		    
		  
And that's it.
Note The push notification registration ID will not be sent to the Hipmob server until a chat session is opened for the first time.

Details

The push notification Hipmob sends has the following characteristics:
Badge
The push notification badge value is set to the number of pending messages.
Sound
The push notification sound is set to ping.aiff.
Alert
The push notification alert is set to a JSON dictionary with a single key (body) which is the text generated from the push message text setting in the Hipmob management interface.
Payload
A custom JSON dictionary is set for the payload with the action key set to the value com.hipmob.push.NEW_MESSAGE: this can be used to differentiate Hipmob push notifications from push notifications sent by other tools. If a custom user identifier was set this will be the value of the devicekey key in the payload.

Testing

To test that the push notifications are properly setup you can use the Hipmob management interface to send a message to a device. Log into the Hipmob management interface and visit the Devices tab (at https://manage.hipmob.com/#devices).

Figure 13: Devices tab

Find the device you want to send a message to, and then expand the device's menu and select Send Message.

Figure 14: Send Message

Type in the message text, and then click Send.

Figure 15: Message sent

On the iOS device, the push notification will be received and displayed using the configured notification text. The count of available messages is been included in the message and the application's badge count is set.

Figure 16: push notification delivered

When the notification is tapped on, the application will be launched.

Figure 17: opening the App from the push notification