nativescript-estimote-plugin
由 joma 编写 | v0.0.6
为 Nativescript 提供的 Estimote SDK 插件
npm i --save nativescript-estimote-plugin

原始仓库: "https://npmjs.net.cn/package/nativescript-estimote-sdk"

NativeScript 的 Estimote 插件

Estimote 信标是一个非常小巧的设备。它拥有强大的 32 位 ARM® Cortex M0 CPU 和 256kB 闪存,加速度计、温度传感器,最重要的是 – 一个 2.4 GHz 的蓝牙 4.0 Smart(也称为 BLE 或蓝牙低功耗)双向无线电。

你可以将信标想象成一个安装在固定位置的微型灯塔,向周围的所有船只(智能手机)广播其存在。它们可以距离2英寸近,也可以距离230英尺(约70米)远。

此插件在 Estimote 原生 SDK 的基础上实现,让你可以追踪你周围的信标设备。它定义了一个全局的 estimote 对象,该对象定义了用于追踪信标设备的各种操作。

先决条件

NativeScript 1.5+(tns --version),如需升级,请升级。

安装

从命令提示符进入您的应用程序根目录并执行

tns plugin add nativescript-estimote-plugin

方法

  • estimote.startRanging
  • estimote.stopRanging

您可以使用以下方式初始化插件以针对区域

var Estimote = require('nativescript-estimote-plugin');

var options = {
  region : 'Progress', // optional
  callback : function(beacons){
    /* This is called everytime beacons are discovered or proximity changes

      for (var i = 0; i < beacons.count; i++) {
         var beacon = beacons[i];
         if (beacon.major > 0){
             var distance = "NA";
             var identifier = "Major:" + beacon.major + " Minor:" + beacon.minor;

             if (beacon.proximity) {
               distance = beacon.proximity;
             }

             items.push({
                 "proximity" : beacon.proximity,
                 "identifier": identifier,
                 "distance":  "Distance: " + distance,
                 "rssi": "Power: " +  beacon.rssi + "dBm"
             });

             console.log(json);
         }
    }
  */
}

var estimote = new Estimote(options);

estimote.startRanging

此方法初始化 estimote 信标管理器以监视指定区域内的信标。

estimote.startRanging();

如果已存在具有相同标识符的现有区域,并且该区域正在由应用程序监视,则旧区域将被新区域替换。您使用此方法添加的区域将与应用程序中所有信标和位置管理器对象共享。

estimote.stopRanging

此方法停止 estimote 信标管理器监视信标。

estimote.stopRanging();

平台

  • iOS (NativeScript 1.5+)
  • Android (NativeScript 1.5+)