Push notification

Guide on push service in iOS using APNS(Apple Push Notification Service) through kakao platform service. Here, we discuss instruction on using APNS and Push service based on Kakao Account login.
Using Kakako iOS SDK, you can push without managing user id. Only through KakaoAccount login only Without having to additionally managing user id, you can now send push and for such, you can easily register push token and delete it easily.

For details on kakao push service, refer to guide REST API push notification.
If developing service is not purely based on kakao account but is based on other account management system or other SNS service, it is recommended to call REST API directly when using push notification service.

Getting started

In order to use push notification correctly in kakao platform service, following procedures must be followed. Following is general guide to using APNS.

  • Issue APNS certificate: In order to use APNS, you need a certificate from Apple, which has been registered. This is a detail guide on issuing APNS certificate.
  • Kakao Push service setting: This is a detail guide on APNS certificate registration in order to use Kakao platform provided push service
  • APNS registration and issuing push token: This is a guide for registering APNS in application for remote notification, and issuing push token.
  • Receive push notification: Guide on building application for remote notification. If you you implement with kakao account login, following functionalities are supported in order to help build push service. In following SDk, API and sample for building such system is included.
  • Register push token: Register push token with push system provided through kakao platform service. Login users can receive push upon registration.
  • Unregister push token: Unregister push token with push token provided through kakao platform service. Login users will no more receive push upon deregistration.
  • Lookup push token information: If you have registered correct push token in kakao platform service, you can look up token you are using.
  • Send push notification: This describes sending push through SDK.
  • Launch sample app: Instructions on launching sample app which is included in SDK.

Settings

Issuing APNS Certificate

APNS certificate file is used in a server in which push is sent in order to use Apple push service. Sever for sending push notification will be provided by kakao platform service and certificate file must be registered in kakao platform service. Following describes on issuing APNS certificate of .p12 type

In Kakao push service .p12 type APNS certificate file is supported. If you already own APNS certificate(.p12) you can skip this step.

Creating App ID

Each iOS application contains unique application ID. This will explain on how to create APP ID for push notification service.

If there is App ID already in existence, following procedure can be skipped.

  1. Log in to Apple developer center. Redirect to Apple developer center

  2. Click on iOS provisioning portal located at top right(iOS Developer Program > Certificates, Identifier & Profiles). push_gen_cert1

  3. Click on Identifiers on left in order to look in to the list with ID included(iOS Apps > Identifiers). push_gen_cert2

  4. In order to create new App ID, open App IDs tab and click on create button(+) on the right side(iOS App IDs > +). push_gen_cert3

  5. Record name in App ID Description and correctly input Bundle ID(Wildcard(*) ID can not be used in push notification service). Click on Push Notifications below with checking checkbox and press continue Continue. push_gen_cert4 push_gen_cert5

  6. If you have set everything correctly, you can retrieve App ID information correctly. Continuously click on Submit button. push_gen_cert6

Creating Certificate request

In order to issue certificate, you need certificate request file. You can retrieve this file by creating one in Keychain Access App in Mac OS X.

  1. Launch Key chain access app. push_cert_req1

  2. In menu access keychain > Certificate support > request certificate from certificate issuer. push_cert_req2

  3. Enter required information, and click on checkbox of "Saved to disk". Click on continue button. push_cert_req3

  4. Save certificate request file. push_cert_req4

Setting App ID for push notification

Using created certificate request file, you can use it to set push in Apple developer center. Once App ID is creaed, it is required to make seperate setting for push notification.

  1. By seliecting created/existing App ID for push notification setting, click on Edit button. push_cert_conf1

  2. Check if checkbox is Enabled in Push Notifications category, located below the page. Check the box if it has not been checked yet. As picture show, two type of certificates can be created. Click on Create Certificate in Production SSL Certificate. push_cert_conf2

    You must use Production SSL Certificate in order to use Kakao platform service's push notification.

  3. If following setup wizard page appears, please click on Continue button. push_cert_conf3

    4.Creating and savingSelect on certificate requested file created previously and click on Generate button. push_cert_conf4

  4. SSL has been created. Press the done button. push_cert_conf5

Sending and installing APNS certificate

In order to register issued certificate, this explain on how to export this in .p12 certificate.

  1. If you have set correctly, you can now download certificate. If you double click on downloaded certificate, installation of app for accessing keychain. push_cert_save1

  2. If you launch keychain access app, you will see certificate which you have installed where login, certificate is located. In the list, if you click on certificate, you will see your personal key. Such certificate and personal key should be selected (select two) from the list. Click on the right button of your mouse and click on "send 2 category". push_cert_save2

  3. Select the path to save .p12 file and enter its name. push_cert_save3

  4. Enter password in order to export it. push_cert_save4

    Unlike export procedure, where empty password is supported, in Kakao push service, you must enter password you wish to use.

As last procedure, enter admin password for your local computer. push_cert_save5

All have been set for APNS certificate.

Setting Kakao Push service setting

In order to use kakao push service correctly APNS certificate and passwordis needed

In setting > push, please turn on push function and upload certificate followed by entering password. dev_015_ios.png

Correct password (password you have set when setting certificate) must be enetered on selected certificate in order to finish the steps.

Basic set up for using kakao push service is set.

App development

For details on registering APNS and push notification, please refer Apple's official guide for push notification.

Issuing push token and registering APNS

In order to send and receive push back and forth in real usage, push token(device token) must be retrieved through registering APNS in iOS application user code.

Since issued device token can be modified in many circumstances, when ever application is launched, UIApplication's registerForRemoteNotificationTypes: method must be reregistered. If registration has suceeded, device token can be transmitted through application:didRegisterForRemoteNotificationsWithDeviceToken: in app delegate

Since device token is used when sending message, Kakao push service must be notified through REST API. In order to use REST API for registering device token correctly, admin key is needed and it must be called from server side, not from the application side.

For details regarding push notification using REST API REST API's push notification guide, follow.

Following is an example code for registering APNS in iOS application and receiving push token.

//============================================
//  Written in Application Delegate
//============================================

- (void)application::(UIApplication *)app didFinishedLaunchingWithOptions:(NSDictionary*) launchingOptions {

    // Need to be dealt if launched through Push Noti.

    // Requesting push token(Device Token) in Apple server
    UIApplication *sharedApplication = [UIApplication sharedApplication];
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0f) {
        [sharedApplication registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge | UIRemoteNotificationTypeSound |UIUserNotificationTypenotification) categories:nil]];
        [sharedApplication registerForRemoteNotifications];
    } else {
        [sharedApplication registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypenotification)];
    }
}

// Delegation methods
// Created Push token
- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken {
    const void *devTokenBytes = [devToken bytes];
    self.registered = YES;
    [self sendProviderDeviceToken:devTokenBytes]; // custom method
}

// Failed to create Push token
- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err {
    NSLog(@"Error in registration. Error: %@", err);
}

For more codes and details follow official guide on Apple push notficiation of "Registering to Receive Remote Notifications"

Receiving push notification

Push notification can be received in following scenario.

  • If application is unable to run in foreground: iOS system alert push through notification, badge, sound and more. If user tab on such notification, system will launch application in which aroused the notification and will launch application:didFinishLaunchingWithOptions:(If implemented) of delegate의
  • When application is running: targeted application's :didReceiveRemoteNotification: Method will be called which is of delegate.
//============================================
//  Created in Application Delegate
//============================================



// While launching app, this is the part where it should deal with receiving Push
- (void) application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*) userInfo {

    NSLog(@"Received Push Notification: %@", [userInfo description]);
    // Dealing with what to be done after

}

For details on code and contents, refer to Apple's official guide for push notification의 "Handling Remote Notifications".

Register push token

This guide is for registering push token(Device Token) in Kakao Push system. Push token registration in iOS SDK is based on user token created through Kakao Account login. As such, before registering push token, you must be logged in with Kakao Account. If you have issued token without logging in, you must keep your token registration in future login.

There are differences with AdminKey type push token registration REST API.

  • This works based on user token which means this does not take users unique ID seperately.
    (Refer to User ID in User information request)
  • device id uses push token value.

There is a difference between completionHandler and other methods. Value, expiredAt, is for expiration date in Kakao push system. -1 means unlimited.

Example follows.


#import <KakaoOpenSDK/KakaoOpenSDK.h>

(Skipped)

// Called when registering device token
- (void) registerDeviceToken:(NSData*) deviceToken  {

    //SDK provided push token registration method

    [KOSessionTask pushRegisterDeviceWithToken:deviceToken
                             completionHandler:
        ^(BOOL success, NSInteger expiredAt, NSError* error){
            // what is to be after is implemented here
        }];

}

Disabling push token registration

There are two ways to unregister push token. It is possible to either unregister push token of current device's or to unregister push token of all of devices in current user.

Disabling push token of current device's

Like the push token registration, this is also log in based. AdminKey based push token deletion through REST API only take in device id and user unique ID. But in case of SDK, only takes in push token. Since you have used push token as device id while registering SDK internally, you must use push token as device id again when unregistering.

Recommended in following condition.

  • When set to not receive push from certain device any longer.
  • When logging out from certain device.

Example follows.

- (void) deregisterCurrentDevice:(NSData*) deviceToken {

    //unregistration of SDK provided push token
    [KOSessionTask pushDeregisterDeviceWithToken:deviceToken
                               completionHandler:
        ^(BOOL success, NSError* error){
            // What is to be after is implemented here
        }];

}
Unregistering all of certain users device's push token

This is also log in based, just like the Push token registration/unregistration of current device. Must unregister all of push token in devices of user logged in currently.

This is supported in following cases.

  • When you wish to not receive push from all of devices
  • When unregistering

Example follows.

- (void) deregisterAllDevice {

    //Unregistration method of push token in all of devices, provided by SDK
    [KOSessionTask pushDeregisterAllDeviceWithCompletionHandler:
        ^(BOOL success, NSError* error){
            // What is to be after is implemented here
        }];

}

Push token information lookup

Able to look up on whether push token is registered in kakao platform service or what other push token exists related to current user. User token is needed to use this functionality which can be retrieved after successful login.

Succession result is provided through NSArray, including multiples of KOPushTokenInfo, and KOPushTokenInfo information is as below.

Elements Type Description
userId NString Registered push token user id
deviceId NString Registered push token user id
pushToken NString Registered push token
pushType NString Push token type. For example, "apns" or "gcm"
createdAt NString Time in which push token was created
updatedAt NString Time in wich push token renewal happened

Example follows.

[KOSessionTask pushGetTokensTaskWithCompletionHandler:^(NSArray *tokens, NSError *error) {
    if (!error) {
        // success
        // KOPushTokenInfo objects are included in tokens array.
        // ...
    } else {
        // error
    }
}];

Sending push notification

This works based on login, as exactly as how push token registration/unregistration is based. SDK provided method for sending push is implemented in a way in which push can be sent to only user him or her self.

Ways to send push from A user to B user, please refer to REST API Push notification.

Detail information regarding parameter, please refer to Sending push notification REST API.

Example follows.


- (void) invokeSend {

    // Custom information in which will be sent with push notification
    NSDictionary* customField =
        [NSDictionary dictionaryWithObjectsAndKeys:
            @"value1", @"key1",
            @"value2", @"key2",
            nil];

    // Data that will be received by iOS device
    KakaoPushMessagePropertyForApns* forApns =
        [[KakaoPushMessagePropertyForApns alloc]
            initWithBadgeCount:10
            sound:@"default"
            pushnotification:YES
            messageString:@"Is push correctly sent?"
            customField:customField];

    // Data that will be received by Android device
    KakaoPushMessagePropertyForGcm* forGcm =
        [[KakaoPushMessagePropertyForGcm alloc]
            initWithCollapse:@"collapse_id_1234"
            delayWhileIdle:NO
            returnUrl:@"http://www.example.com/gcm_feedback"
            customField:customField];

    // SDK's send method parameter value
    KakaoPushMessageObject* pushMsg = [[KakaoPushMessageObject alloc]
        initWithApnsProperty:forApns
        gcmProperty:forGcm];

    // Sending push
    [KOSessionTask pushSendMsg:pushMsg
        completionHandler:^(BOOL success, NSError* error){
            // What is to be after is implemented here
        }];

}

Launching sample app

Explanation on launching PushSample app included in SDK. Push functionality provided by kakao platform service have restrictions compare to other functionalities supported by Kakao platform service.

Launch in iOS device

If this is ran in simulator, following problems will occur.

  • Unable to issue Device Token
  • Unable to receive Push
Use APNS Production SSL certificate

APNS Development SSL certificate is not supported in kakao platform service's developer website (Will support Development SSL in future). Only APNS Production SSL certificate can be registered. Because only APNS Production SSL certificate is supported, in order to launch push sample correctly in a device, Code signing should be Distribution not developer when doing the Build.

Procedures for launching PushSample app
  • Todo at Apple Developer
    • Register app in Apple Developer
    • Adding Production SSL certificate in Push Notification settings
    • Distribution(Ad Hoc) Provisioning Profile creation

For issuing certificate, refer Issue APNS certificate.

  • [Kakao Developers_] (https://developers.kakao.com)To do
    • Creating app(or edit)
    • After adding iOS platform, bundle ID(Bundle Identifier) should be entered as it should correctly. Last line of bundle id will be set as "PushSample". Example) your.unique.bundle.id.PushSample
    • Registering APNS Production SSL and enabling Push usage
  • Modifying PushSample App
    • Editing Bundle Identifier. Bundle ID in sample is "com.kakao.sample.${PRODUCT_NAME:rfc1034identifier}", which is of "com.kakao.sample.PushSample". For this reason, when app is created, edit with Bundle ID added in iOS platform. Last ${PRODUCT_NAME:rfc1034identifier} means PushSample. Example) your.unique.bundle.id.${PRODUCT_NAME:rfc1034identifier}
    • In URL scheme, apply native app key as well. Example) kakao0123456789abcdefghijklmno
    • Change to native app key, created for KAKAO_APP_KEY property. Example) 0123456789abcdefghijklmno
    • Build Settings > In code signing section, select distribution certificate from code signing
    • Select provisioning profile created from previous steps

For registering certificate, follow Kakao Push service setting.
For app creation and app key related settings, follow Creating app.


Last Modified : 2017-08-03