Adding Push Notification

The Thing-IF SDK uses the push notification for receiving the response from the things. For iOS, Kii Cloud provides the push notification via Apple Push Notification service (APNs). You need to make some APNs-related configuration and prepare your build environment besides configuring Kii Cloud.

See Overview of the Push Technology for iOS for the technical overview of APNs.

Initialization of push notification is not required if your mobile app does not manage end nodes but only the gateway which interacts with Thing Interaction Framework.

By following the description in this page, you will be ready to receive push notifications from Kii Cloud.

Setting up

You need to complete various configurations in order to enable push notification with APNs. Kii recommends you to follow the instructions in the tutorial because such configurations and implementations of push notification are complicated.

First, in order to make push notification functional, follow the steps described in iOS Push Notification Tutorial to set up, implement, and test push notification. Skip the steps that you have already done such as integration of the Kii Cloud SDK into your development project. Choose Swift 2.3 in the tutorial because the Thing-IF SDK supports Swift 2.3 only.

After completing the above steps, go to Modification for Thing-IF.

The tutorial explains how to enable the feature in the development environment. You need to enable it in the production environment in a similar way before you release your mobile app. Also, note that the tutorial does not cover the instruction for integrating the Thing-IF SDK. You need to integrate the Thing-IF SDK to your project for the Thing-IF SDK features.

Modification for Thing-IF

Once you are done with the tutorial, we will remove lines that are unnecessary for mobile apps with the Thing-IF SDK. Replace the lines for device installation that use the Kii Cloud SDK API with those that use the Thing-IF SDK API. This is because the method for device installation is different between the two SDKs.

Remove the call of the KiiPushInstallation.installWithDeviceToken method from the application:didRegisterForRemoteNotificationsWithDeviceToken: method in the AppDelegate class. The code below reflects the removal.

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
  let username = "user1"
  let password = "123ABC"
  KiiUser.authenticate(username, withPassword: password) { (user: KiiUser?, error: NSError?) -> Void in
    if (error != nil) {
      print("Failed to authenticate: \(error!.userInfo["description"])")
      return
    }

  }
}

Leave the sample code as the above for now. We will insert the API call for Thing-IF later. See Installing a device in the Initializing and Onboarding topic for more information.

Also, according to the specification of your mobile app, rewrite the login processing that uses user1 for testing. The sample code in the Initializing and Onboarding topic uses a pseudo user as a thing owner. If you implement a login screen where an explicit owner user logs in, move the above login processing to the processing class of the login screen. Also, update the program structure so that you can use deviceToken that contains the device token from APNs after the owner logs in.

Customizing a push notification

Some of the APIs used in the initialization of push notification are iOS APIs. They do not depend on Kii Cloud.

You can also customize the way that push notification works by using the APNs features such as categories. For implementation, see Initializing APNs in the push notification topic for the Kii Cloud SDK.