8.0.1 • Published 2 years ago

kinvey-nativescript-sdk v8.0.1

Weekly downloads
140
License
Apache-2.0
Repository
github
Last release
2 years ago

Kinvey NativeScript SDK

Installation

From the command prompt go to your app's root folder and execute:

npm i kinvey-nativescript-sdk

Usage

Initialize SDK

We need to initialize the SDK before your app starts, so open app.js and add this before application.start();:

JavaScript

import * as Kinvey from 'kinvey-nativescript-sdk';

Kinvey.init({
  appKey: '<yourAppKey>',
  appSecret: '<yourAppSecret>'
});

TypeScript

import * as Kinvey from 'kinvey-nativescript-sdk';

Kinvey.init({
  appKey: '<yourAppKey>',
  appSecret: '<yourAppSecret>'
});

Angular

Import the KinveyModule in your app.module.ts like this to initialize the SDK:

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

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

Then you can use dependency injection to inject a Kinvey service in your module like this:

import { Component } from '@angular/core';
import { UserService } from 'kinvey-nativescript-sdk/angular';

@Component()
export class AppComponent {
  constructor(private userService: UserService) {}

  async login() {
    try {
      const user = await this.userService.login('<username>', '<password>');
      console.log(user);
    } catch (error) {
      console.log(error);
    }
  }
}

The following services are available to use with dependency injection:

  • DataStoreService
  • EndpointService
  • FilesService
  • PingService
  • UserService

Push

You will need to install nativescript-plugin-firebase and follow the instructions at https://github.com/EddyVerbruggen/nativescript-plugin-firebase#prerequisites on how to setup your app. Make sure to require the nativescript-plugin-firebase plugin in your app.ts file as shown in the example app.

You can then use the Push module to register the device running your app like this:

import * as Push from 'kinvey-nativescript-sdk/push';

function receivedPushNotificaiton(message) {
  console.log("Title: " + message.title);
  console.log("Body: " + message.body);
  // if your server passed a custom property called 'foo', then do this:
  console.log("Value of 'foo': " + message.data.foo);
}

Push.register(receivedPushNotification)
  .then((deviceToken) => {
    console.log(`The device with device token ${deviceToken} is registered for push.`);
  })
  .catch((error) => {
    console.log(error);
  })

To unregister the device running your app do this:

import * as Push from 'kinvey-nativescript-sdk/push';

Push.unregister()
  .then((deviceToken) => {
    console.log(`The device with device token ${deviceToken} has been unregistered for push.`);
  })
  .catch((error) => {
    console.log(error);
  })
Angular

You will need to import the KinveyPushModule in your app.module.ts like this:

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

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

Then you can use dependency injection to inject the PushService in your module like this:

import { Component } from '@angular/core';
import { PushService } from 'kinvey-nativescript-sdk/angular/push';

@Component()
export class AppComponent {
  constructor(private pushService: PushService) {}

  receivedPushNotificaiton(message) {
    console.log("Title: " + message.title);
    console.log("Body: " + message.body);
    // if your server passed a custom property called 'foo', then do this:
    console.log("Value of 'foo': " + message.data.foo);
  }

  async registerForPush() {
    try {
      const deviceTokne = await this.pushService.register(this.receivedPushNotification);
      console.log(`The device with device token ${deviceToken} has been unregistered for push.`);
    } catch (error) {
      console.log(error);
    }
  }
}

Build

If you would like to build the SDK yourself, clone the monorepo, then:

  • npm i
  • npm run build

You can then install the SDK build by running npm i /<localpath>/packages/nativescript-sdk

8.0.1

2 years ago

6.1.2

2 years ago

6.1.4

2 years ago

6.1.3

2 years ago

7.0.3

2 years ago

8.0.0

2 years ago

7.0.2

2 years ago

7.0.1

2 years ago

7.0.0

3 years ago

6.1.1

3 years ago

6.1.0

3 years ago

6.0.1

3 years ago

6.0.0

3 years ago

5.0.1

4 years ago

5.0.0

4 years ago

4.2.5

5 years ago

4.2.5-next.1

5 years ago

4.2.3

5 years ago

4.2.2

5 years ago

4.2.1

5 years ago

3.12.7

5 years ago

3.12.7-next.2

5 years ago

3.12.7-next.1

5 years ago

4.2.0

5 years ago

4.1.0

5 years ago

4.0.0

5 years ago

3.13.0-next.39

5 years ago

3.13.0-next.38

5 years ago

3.13.0-next.37

5 years ago

3.13.0-next.36

5 years ago

3.13.0-next.35

5 years ago

3.13.0-next.34

5 years ago

3.13.0-next.33

5 years ago

3.13.0-next.31

5 years ago

3.13.0-next.30

5 years ago

3.13.0-next.29

5 years ago

3.13.0-next.28

5 years ago

3.12.6

5 years ago

3.12.5

5 years ago

3.13.0-next.27

5 years ago

3.13.0-next.26

5 years ago

3.13.0-next.25

5 years ago

3.13.0-next.24

5 years ago

3.13.0-next.23

5 years ago

3.13.0-next.22

5 years ago

3.13.0-next.21

5 years ago

3.13.0-next.20

5 years ago

3.13.0-next.19

5 years ago

3.13.0-next.18

5 years ago

3.13.0-next.7

5 years ago

3.12.4

5 years ago

3.13.0-next.6

5 years ago

3.13.0-next.5

5 years ago

3.13.0-next.4

5 years ago

3.13.0-next.3

5 years ago

3.13.0-next.2

5 years ago

3.13.0-next.1

5 years ago

3.13.0-next.0

5 years ago

3.12.3

5 years ago

3.12.2

6 years ago

3.12.2-next.1

6 years ago

3.12.2-next.0

6 years ago

3.12.1

6 years ago

3.12.0

6 years ago

3.11.7

6 years ago

3.11.6

6 years ago

3.11.5

6 years ago

3.11.4

6 years ago

3.11.3

6 years ago

3.11.2

6 years ago

3.11.1

6 years ago

3.11.0

6 years ago

3.10.4

6 years ago

3.10.3

6 years ago

3.10.2

6 years ago

3.10.1-beta.1

6 years ago

3.10.1

6 years ago

3.10.1-beta.0

6 years ago

3.10.0

6 years ago

3.9.10

6 years ago

3.9.9

6 years ago

3.9.7

6 years ago

3.9.6

6 years ago

3.9.5

6 years ago

3.9.4

6 years ago

3.9.3

6 years ago

3.9.3-beta.8

6 years ago

3.9.3-beta.7

6 years ago

3.9.2

7 years ago

3.9.2-beta.9

7 years ago

3.9.2-beta.8

7 years ago

3.9.2-beta.7

7 years ago

3.9.2-beta.6

7 years ago

3.9.2-beta.5

7 years ago

3.9.2-beta.4

7 years ago

3.9.2-beta.3

7 years ago

3.9.2-beta.1

7 years ago

3.9.1

7 years ago

3.9.1-beta.4

7 years ago

3.9.1-beta.3

7 years ago

3.9.1-beta.2

7 years ago

3.9.1-beta.1

7 years ago

3.9.0

7 years ago

3.9.0-beta.4

7 years ago

3.9.0-beta.3

7 years ago

3.9.0-beta.2

7 years ago

3.9.0-beta.1

7 years ago

3.8.0

7 years ago

3.7.2

7 years ago

3.7.1

7 years ago

3.7.1-rc.1

7 years ago

3.7.0

7 years ago

3.6.0-ns.9

7 years ago

3.6.0-ns.8

7 years ago

3.6.0-ns.7

7 years ago

3.6.0-ns.6

7 years ago

3.6.0-ns.5

7 years ago

3.6.0-ns.4

7 years ago

3.6.0-ns.3

7 years ago