Starting Your First App

This guide shows you how to set up a project. If you are coming from any of the samples, note that (most of) these steps have already been done ahead of time.

Platform Compatibility

We test our SDK against the following platforms:

  • iOS
  • Android

The minimum version supported for each platform depends on the version of NativeScript. NativeScript versions 7.x and above are supported with Kinvey SDK version 6.x and above. NativeScript versions 5.x and 6.x are supported with Kinvey SDK versions 5.x or below.

Add an App Backend

If you don't have an account on Kinvey yet, please signup before continuing.

In the Kinvey console, create a new app backend. If you are currently viewing another app backend, click the app's name in the left navigation, and the select "New App" in the menu.

On the app dashboard page, you will find your App Key and App Secret in the top right. You’ll need those to configure your app.

Create a NativeScript app

You can set up your app using the command line.

Using the Command Line

If you prefer to use command line tools, follow the NativeScript Getting Started Guide to set up the CLI.

Add Kinvey SDK

You can add the Kinvey SDK by installing it with npm.

Use the following command to add the SDK as a plugin to your NativeScript app:

npm i --save kinvey-nativescript-sdk

Configure Your App

To use the SDK, you need to initialize it with your App Key and App Secret.

import * as Kinvey from 'kinvey-nativescript-sdk';
Kinvey.init({
    appKey: '<appKey>',
    appSecret: '<appSecret>'
});
var Kinvey = require('kinvey-nativescript-sdk');
Kinvey.init({
    appKey: '<appKey>',
    appSecret: '<appSecret>'
});

The initialization function accepts the following options when initializing the library:

OptionDescription
appVersionSet a version for your app that will be sent as the header X-Kinvey-Client-App-Version on every network request.
defaultTimeoutSet the default timeout used for all requests. The value must be in milliseconds. The default value is 60000 ms (1 minute).
storageSelects a storage provider. Possible values: Kinvey.StorageProvider.SQLite (default), Kinvey.StorageProvider.Memory.

Customers with dedicated Kinvey instances and Progress Health Cloud customers need to set instanceId to the ID of their dedicated Kinvey instance to correctly setup the backend and Mobile Identity Connect API URLs for the library.

You can find your Instance ID on the dashboard of the Kinvey Console, next to your App Key and App Secret.

import * as Kinvey from 'kinvey-nativescript-sdk';
Kinvey.init({
    appKey: '<appKey>',
    appSecret: '<appSecret>',
    instanceId: '<instanceId>'
});
var Kinvey = require('kinvey-nativescript-sdk');
Kinvey.init({
    appKey: '<appKey>',
    appSecret: '<appSecret>',
    instanceId: '<instanceId>'
});

Example of an instanceId would be:

instanceId: 'kvy-us2'

Never use the Master Secret in client-side code.

Another way to pass options is to set them in the package.json file and then call init() without arguments. However, any options that you set inside the method call will overwrite the values set in package.json.

The SDK initialization options are located inside the kinvey-nativescript-sdk plugin configuration section of package.json and carry the same names as the init() arguments.

"pluginsData": {
  "kinvey-nativescript-sdk": {
    "config": {
      "appKey": "kid_S...--qCb",
      "appSecret": "d0b8e416e3e...e1987f5945315b8906"
    }
  }
}

Verify Set Up

Your app is now connected to Kinvey. The ping method, as shown below, will contact the backend and verify that the SDK can communicate with your app.

Kinvey.ping()
    .then((response) => {
        console.log(
            `Kinvey Ping Success. Kinvey Service is alive,
            version: ${response.version}, response: ${response.kinvey}`);
    })
    .catch((error) => {
        console.log(`Kinvey Ping Failed. Response: ${error.description}`);
    });
Kinvey.ping()
    .then(function(response) {
        console.log(
            'Kinvey Ping Success. Kinvey Service is alive, version: '
            + response.version + ', response: ' + response.kinvey);
    })
    .catch(function(error) {
        console.log('Kinvey Ping Failed. Response: ' + error.description);
    });

If the response just yields hello instead of hello app-name, please make sure you have configured your app. If the error yields This app backend not found, the app key and app secret you entered are incorrect.

NativeScript Angular

Follow the same steps above to add the Kinvey NativeScript SDK to your application. For more complete guides on using the Angular API please take a look at our Angular Guides.

Remember to use kinvey-nativescript-sdk/angular to import the sdk instead of kinvey-angular-sdk.

Initialize the SDK

You will need to add the KinveyModule to the imports in your app.module.ts.

import { NgModule } from '@angular/core';
import { KinveyModule } from 'kinvey-nativescript-sdk/angular';

@NgModule({
  imports: [
    KinveyModule.init({
      appKey: '<appKey>',
      appSecret: '<appSecret>'
    })
  ]
})
export class AppModule { }

Every App has an Active User

Your app will be used by a real-life human being. This person is represented by the Active User. This user object must explicitly be created, either with a username and password, OAuth sign-on (such as Facebook, Google+, LinkedIn, etc.), or Mobile Identity Connect. See the User Guide for more information.

What's next

You are now ready to start building your awesome apps! Next we recommend diving into the User Guide or Data Store Guide to learn more about our service, or explore the sample apps to go straight to working projects.

Related Samples