Mini App JS SDK

The Mini App SDK for JavaScript can be used to access Android/iOS device and App specific features from a Mini App. It is intended to be used in conjunction with the Android Mini App SDK and iOS Mini App SDK.

Getting Started

1. Setup the SDK

This SDK can be used either as an NPM module or via the bundled script file.

Usage as NPM module

The SDK package can be installed in your project from the NPM registry:

npm install js-miniapp-sdk

And then it can be used as an import in your project:

import miniApp from "js-miniapp-sdk";

miniApp.getUniqueId()
    .then(id => {
    // ...

Usage via bundled script

You can alternatively use the bundled script file to use the SDK. When using the bundled script file, a global MiniApp object will be available for using the SDK.

First, download the bundled script file from the releases page. You can then include it as a normal <script> tag in your HTML:

<script src=“miniapp.bundle.js></script>

Then you can acces the SDK methods via window.MiniApp.

window.MiniApp.getUniqueId()
    .then(id => {
    // ...

2. Retrieve a unique ID

You can retrieve a unique ID which was generated by the Android or iOS App:

miniApp.getUniqueId()
	.then(id => {
		console.log(id);
	}).catch(error => {
		console.error(error);
	});

Advanced Usage

Usage when testing in the browser

Currently, the SDK does not support testing in the browser. You must test using the Android Mini App Demo App or iOS Mini App Demo App on an actual Android or iOS device.

If you wish to be able to test in a browser, you can detect whether your web app is running on an Android/iOS device or in the browser. If not running on a device, you can return a mock value instead of calling the SDK method. Device detection can be done using something like Bowser.

import miniApp from "js-miniapp-sdk";
import Bowser from "bowser"; 

const browser = Bowser.parse(window.navigator.userAgent);

function getId() {
    if (browser.is("android") || browser.is("ios")) {
        return miniApp.getUniqueId()
            .then(id => {
                console.log(id);
            }).catch(error => {
                console.error(error);
            });
    } else {
        return Promise.resolve("mock_unique_id_value");
    }
}

Changelog

v1.0.0 (2020-5-13)