Create an iOS App
First, let us create a new mobile app and integrate the Kii Cloud SDK. Let us also do a quick test to see if the SDK is integrated correctly.
We will create a new iOS app with Xcode.
From the initial Xcode screen, select "Create a new Xcode project". Use the following settings.
- Use the "Single View Application" template in the "iOS" tab, though you can use any project template.
Enter the following information as the project settings:
- Product Name:
- Team: The name of the user or organization that can use the Apple Developer website
Organization Identifier: The identifier to be used for distributing the iOS app
Specify an identifier that contains a real domain name, though
com.exampleis used in this tutorial. This is because the product name and organization identifier are concatenated to create a bundle identifier that will be automatically registered to the Apple Developer website.
Language: "Objective-C" or "Swift"
Select your preferred language. Select "Swift" if you use the Thing-IF SDK. This tutorial provides sample code in Swift 3 and Objective-C.
- Product Name:
After you create a project, configure the code signing settings in Xcode.
In order to test the push notification feature, you need to sign and run the execution module on a real device. By working together with Apple's server, Xcode 8 or later allows you to enable automatic code signing. This tutorial uses this feature as well.
Confirm that the "Signing" section in the project settings are configured as below:
- "Automatically manage signing" is enabled.
- Your team is displayed in the "Team" field.
If you cannot choose your team in the "Team" field, choose "Xcode" > "Preferences" > "Accounts". Confirm that the account registered as a member of the Apple Developer Program is displayed.
After you review the "Signing" section, try to run the mobile app to check if the settings are correct.
- Connect an iPhone device to the development machine. When you connect it for the first time, follow the on-screen instruction to configure a trust relationship for debugging.
- Choose "Product" > "Destination", and select the connected device.
- Choose "Run" on the toolbar or in the "Project" menu to run the mobile app.
The test is a success if the mobile app starts and the screen that you selected from the project templates opens. An empty screen opens if you selected the "Single View Application" template.
If the mobile app does not run correctly, there is something wrong with the development environment. Double check the environment and solve the issue.
Perform the following actions if you want to manually sign code by disabling the "Automatically manage signing" option or if you use Xcode 7 that does not support automatic code signing. You can skip these actions if you follow the default steps of the tutorial. The tutorial uses the automatic code signing feature.
- Issue an App ID that matches the bundle identifier.
- Issue a development certificate and install it in Keychain Access.
- Register the device's UUID for debugging
- Create a provisioning profile
- Configure the development certificate and provisioning profile in the "Signing" section in Xcode
Refer to the flow diagrams in Using APNs if you manually perform these actions.
We will now prepare the Kii Cloud SDK by following the steps described in the iOS Quick Start guide.
Follow the quick start guide link in each step to see the detailed procedures. Once you've followed the procedures in the quick start guide, come back to this page and proceed to the next step.
We will integrate the SDK in the following two steps:
Create an application in Kii Cloud
Log in to the Kii Cloud developer portal and create a new application. The push notification will be executed under this application.
- Set an easy-to-remember application name, like "Push Notification".
- Set the server location to the nearest region from where you are going to distribute the application.
After the application is created in Kii Cloud, you will get the AppID for identifying the application.
Open Creating a Kii Application and complete all the steps excluding the section "Adding collaborators". When you are done, come back to this page and proceed to the next step.
Integrate the Kii Cloud SDK
Integrate the Kii Cloud SDK in the iOS application you've created in the previous step.
Open Adding the Kii Cloud SDK and complete all the steps. When you are done, come back to this page and proceed.
At this moment, you should be able to call Kii Cloud APIs in your application. To check if the SDK is integrated correctly, we will now create a new user as a test.
The user we create here will be used later. In Kii Cloud, the destination of push notifications is a user, so we need to create a user beforehand.
We will create a new user with the following fixed username and password for now (in developing a real application, you would most likely want to create a user in a more practical way; check the implementation tips at the end of this tutorial):
Insert the following code in the place where it can be executed easily, like the
application:didFinishLaunchingWithOptions: method in the AppDelegate.
Here is what is happening in the sample code:
- Execute the
performRegistrationmethod to create a new Kii Cloud user with the fixed username and password.
- Receive the user registration result with a callback method and record the result in a log.
The user registration is successful if the message "Succeeded" pops up after the application is launched. If you launch the application more than once, the "Duplicate entry exists" error will show up since the application will attempt to register the duplicating user. You can ignore the error in this case because the user has already been created.
If you see other error messages, double-check all steps again. For example, make sure that the
beginWithID:andKey:andSite: method is correctly executed to integrate the SDK. Also, make sure that the correct AppID and server location are set.
Once a user is created, the above sample code is no longer needed. Delete or comment out the code.
Build and run your mobile app in Xcode before you proceed to the next topic. To perform tasks described in the next topic on the Apple Developer website, you need to send the information of your mobile app to Apple's server by running the mobile app in Xcode for testing.
Let us move to the next step: Create a Certificate.
|<< iOS Push Notification Tutorial||Create a Certificate >>|