Implementation of the AppDelegate Class

First, we will look into the AppDelegate class.

This class contains only initialization of the Kii Cloud SDK in addition to the code generated by Xcode at the project generation.

The application(_:didFinishLaunchingWithOptions:) method that is called at launch of the mobile app, initializes the Kii Cloud SDK as below:

  • func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
      // Initialize the Kii Cloud SDK.
      Kii.begin(withID: "12345678", andKey: "abcdef0123456789abcdef0123456789", andSite: KiiSite.JP)
    
      return true
    }
  • - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      // Initialize the Kii Cloud SDK.
      [Kii beginWithID:@"12345678"
                andKey:@"abcdef0123456789abcdef0123456789"
               andSite:kiiSiteUS];
    
      return YES;
    }

The Kii.begin(withID:andKey:andSite:) method initializes the SDK. It has three parameters: AppID, AppKey (an arbitrary value), and the server location of the application in order.

There are many applications created by numerous developers on Kii Cloud. To distinguish the applications, Kii Cloud uses the AppID. This value is generated when you create your application on the developer portal.

As illustrated in the figure below, the AppID is to be set in the initialization process of the mobile app. By setting the same AppID, application data and users can be shared across multiple platforms; in the figure, the Android and iOS applications are sharing the same application data and users by using the same AppID 1111.

When you download Hello Kii application from the developer portal, the unique AppID and AppKey for you are assigned and embedded in the zip file automatically. When you open the project, you will find the initialization code, like the one shown at the top of this page, is already embedded.

If you are creating a new project, you need to embed the AppID and AppKey by yourself. To check the AppID, click the gear icon at the upper-right corner of the developer portal to expand the menu icons and click the key icon. The AppID will pop up as follows:

Reminder

It is not possible to attack your application by knowing its AppID. If a malicious user obtains your application's ClientID and ClientSecret, however, they will be able to access all of your application data as the app administrator. The ClientID and ClientSecret, therefore, need to be secured just like the login password of the developer portal.

Be careful when you paste your codes in your posts in places like support communities. Make sure to hide the ClientID and ClientSecret. When you are sending a question to Kii support team, you only need to provide the AppID and server location.


What's next?

Let's check how the login screen is implemented. We will explain how the APIs are used.

Go to Login Screen Implementation.

If you want to learn more...

  • See iOS Quick Start to learn how to configure iOS projects.
  • See Security to learn more about the security. The topic explains why a malicious third party cannot attack your application by knowing its AppID.