This article introduces the Kintone API SDK for iOS. This SDK makes it easier to utilize the Kintone REST API with Swift or Objective-C. This article will explain how to install and run the Kintone API SDK for iOS.
Installation and Setup
Installing the Swift library
There are two ways to install the Swift library: using a package manager (Cocoapods) or building the source code (Carthage). This tutorial uses the package manager in the Xcode Single View App project template for installation.
Create a project with the name sample_project.
Set up the Command Line Tools by going to the XCode menu in the top left corner, then to Preferences, and then Locations. Select Xcode 10.1 in the Command Line Tools setting.
Cocoapods is one of the main package managers. Install Cocoapods through the official site:
Run the following command to create a Podfile in the directory where the project is stored.
Modify the Podfile with reference to the following sample. If the project is not named sample_project, change the sections where sample_project appears to the name of the project.
Install the SDK in the Xcode project by running the following command.
After running the command, a file with the extension sample_project.xcworkspace is generated in the directory. Open this file in Xcode and build it once by navigating to Product and then Build from the top menu. The SDK will be available in the workspace.
Carthage can be installed from Homebrew. Refer to the following GitHub documentation for installation.
Create a Cartfile in the directory where the project is stored with the following command.
Write the following contents in the Cartfile.
After editing the Cartfile, run the following command to download the library.
After the download is complete, the following three frameworks are created in the Sample_project/Carthage/Build/iOS folder.
Import the created framework files into the project with reference to the image below.
The following sample explains the execution method and responses using the sample code found in the Quick Start of the Kintone iOS SDK documentation. This sample will show how to retrieve the details of a single record from a Kintone App. To prepare, create a Kintone App with the field shown below, and generate an API token with view permissions. Refer to the Using API Token authentication article for more information on API tokens. Create a sample record.
Sample Code (File Name: ViewController.swift)
Copy the sample code below and rewrite ViewController.swift in the sample_project folder.
Replace the API token, subdomain, App ID, and record number according to the subdomain in use.
Run the script
Click the upper left ▶︎ mark displayed on Xcode or use ⌘ + R to run the script.
If the request is successful, the record number (in this case, "1") and the value of the text field (in this case, "aaaa") are returned.
Sample Code Explanations
This is an explanation of lines under the Init authenticationAuth comment.
This part defines the authentication method for connecting to Kintone.
There are multiple authentication classes. Password authentication, API token authentication, and basic authentication can be set up.
The authentication has the following priority. (Reference: Kintone REST API Overview)
1. Password authentication
2. API Token authentication
*Session authentication cannot be implemented with the Kintone iOS SDK.
API Token authentication
For an explanation of basic authentication in Kintone, refer to the Configuring IP Address Restrictions and Basic Authentication article in the Kintone Help Center.
The Connection class under the Init Connection without "guest space ID" comment allows the connection to be configured.
Connect to the Kintone environment using the destination domain information and the authentication information created earlier.
The following is an explanation about the lines after the Init Record Module and execute get record API comments.
This part is the process of actually running the Kintone REST API.
In this sample, the getRecord function of the Record class is used to retrieve details of a single record.
The Kintone app ID
The record ID in the Kintone app
In the Record class, there are various functions besides retrieving details of a single record, as will be described in the next section.
This is a class in which the function used in the previous sample code is defined.
Functions have been implemented to get, register, update, delete, and change the status for App records, and to get, register, and delete comments.
The following functions are an example of the functions that can be implemented.
Other functions also exist. Refer to the following document for details.
About Record Class
Multiple APIs can be requested simultaneously for multiple applications.
Refer to the following document for the functions available with BulkRequest.
About BulkRequest Class
Also note the following when running BulkRequest.
- When running BulkRequest to obtain a response, run the execute function.
- Up to 20 functions can be run sequentially excluding the execute function.
This is a class that defines a function to get App information.
Permission to view the App is needed.
Refer to the following document for information about the implemented function.
About App Class
The Kintone iOS SDK uses its own model for each API response.
Check this reference carefully, as constructors and available methods differ.
The Kintone API SDK for iOS makes it easier to run the Kintone REST API when developing applications for iOS or macOS. For questions regarding the use of the Kintone API SDK for iOS, make a post in the Kintone Developer Program community. For feedback or issues, open an issue in GitHub.