Introduction to the iOS SDK

Introduction

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 Xcode

An environment that can install Xcode is necessary for development. If Xcode is not already installed, install the program from the Mac App store.

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.

 

createProject.png

 

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.

 

command-line-tools.png

Cocoapods

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

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.

  • FBLPromises.framework
  • Promises.framework
  • kintone-ios-sdk.framework

Import the created framework files into the project with reference to the image below.

Carthage001.png

Sample Code

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.

Field Type

Field Code

Text

text

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.

Response example

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. 

response.png

Sample Code Explanations

Authentication

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.

Password authentication

API Token authentication

Basic 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.

* Domains created after the September 6, 2019 update are unable to use basic authentication.

Refer to the API Updates for September 2019 for details.

Connection

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.

Record

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.

getRecord(appID, recordID)

Parameters

Name

Type

Required

Description

appID

Integer

yes

The Kintone app ID

recordID

Integer

yes

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.

Optional Features

Record Class

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.

  • getRecord
  • getRecords
  • addRecord
  • addRecords
  • updateRecords
  • deleteRecords
  • updateRecordStatus
  • getComments
  • addComment
  • deleteComment

Other functions also exist. Refer to the following document for details.

About Record Class

https://kintone.github.io/kintone-ios-sdk/reference/record/

BulkRequest Class

Multiple APIs can be requested simultaneously for multiple applications.
Refer to the following document for the functions available with BulkRequest.

About BulkRequest Class

https://kintone.github.io/kintone-ios-sdk/reference/bulk-request/

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.

BulkRequest Sample

Application Class

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

https://kintone.github.io/kintone-ios-sdk/reference/app/

App Sample

Models

The Kintone iOS SDK uses its own model for each API response.
Check this reference carefully, as constructors and available methods differ.

https://kintone.github.io/kintone-ios-sdk/reference/model/app/app/app-model/

Finally

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.

Was this article helpful?
0 out of 0 found this helpful
Do you have any questions or issues related to this article?
Please share your views with us in the Community forums!