npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kinvey-nativescript-sdk

v8.0.1

Published

Kinvey JavaScript SDK for NativeScript applications.

Downloads

309

Readme

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