From 969c4bdad735e3c8b5b29abc09a8e1e9e874b199 Mon Sep 17 00:00:00 2001 From: Alberto Herraiz Date: Fri, 11 Nov 2016 09:28:08 +0100 Subject: [PATCH 1/4] Bugfix: library deprecated for Android fixed! --- Plugin/README.md | 9 ++++++++- Plugin/platforms/android/AndroidManifest.xml | 10 ---------- Plugin/platforms/android/include.gradle | 9 ++++++++- 3 files changed, 16 insertions(+), 12 deletions(-) delete mode 100644 Plugin/platforms/android/AndroidManifest.xml diff --git a/Plugin/README.md b/Plugin/README.md index d1a36ff..2448400 100644 --- a/Plugin/README.md +++ b/Plugin/README.md @@ -16,7 +16,14 @@ From the command prompt go to your app's root folder and execute: ``` tns plugin add nativescript-estimote-sdk +``` +For Android, add these permissions into app/App_Resources/AndroidManifest.xml +``` + + + + ``` ## Methods @@ -34,7 +41,7 @@ You can initialize the plugin for a region in the following way: callback : function(beacons){ /* This is called everytime beacons are discovered or proximity changes - for (var i = 0; i < beacons.count; i++) { + for (var i = 0; i < beacons.length; i++) { var beacon = beacons[i]; if (beacon.major > 0){ var distance = "NA"; diff --git a/Plugin/platforms/android/AndroidManifest.xml b/Plugin/platforms/android/AndroidManifest.xml deleted file mode 100644 index 6c25718..0000000 --- a/Plugin/platforms/android/AndroidManifest.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/Plugin/platforms/android/include.gradle b/Plugin/platforms/android/include.gradle index b4bcb63..fd3e3b3 100644 --- a/Plugin/platforms/android/include.gradle +++ b/Plugin/platforms/android/include.gradle @@ -1,3 +1,10 @@ +android { + productFlavors { + "my-plugin" { + dimension "my-plugin" + } + } +} dependencies { compile 'com.estimote:sdk:0.9.4@aar' -} +} \ No newline at end of file From fb1071ba7040d94173fcbb2874fa34bc8cd7cdbd Mon Sep 17 00:00:00 2001 From: Alberto Herraiz Date: Fri, 11 Nov 2016 09:54:27 +0100 Subject: [PATCH 2/4] Proximity for Android implemented + proximityUUID variable (new param in option) --- Plugin/estimote.android.js | 101 +++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 50 deletions(-) diff --git a/Plugin/estimote.android.js b/Plugin/estimote.android.js index f3b335e..4eea23a 100644 --- a/Plugin/estimote.android.js +++ b/Plugin/estimote.android.js @@ -1,70 +1,71 @@ global.ESTIMOTE_PROXIMITY_UUID = java.util.UUID.fromString("B9407F30-F5F8-466E-AFF9-25556B57FE6D"); global.ESTIMOTE_REGION_NAME = "default"; - var Estimote = (function(){ - function Estimote(options){ - this._regionName = ESTIMOTE_REGION_NAME; - this.callback = options.callback; + function Estimote(options){ + this._regionName = ESTIMOTE_REGION_NAME; + this._proximityUUID = options.proximityUUID ? java.util.UUID.fromString(options.proximityUUID) : ESTIMOTE_PROXIMITY_UUID; + this.callback = options.callback; - if (typeof options.region !== 'undefined'){ - this._regionName = region; - } - var app = require("application"); + if (typeof options.region !== 'undefined'){ + this._regionName = options.region; + } + var app = require("application"); - this.context = app.android.context; + this.context = app.android.context; - this.region = new com.estimote.sdk.Region(this._regionName, ESTIMOTE_PROXIMITY_UUID, null, null); + this.region = new com.estimote.sdk.Region(this._regionName, this._proximityUUID, null, null); - this.beaconManager = new com.estimote.sdk.BeaconManager(this.context); + this.beaconManager = new com.estimote.sdk.BeaconManager(this.context); - var _this = this; + var _this = this; - this.beaconManager.setRangingListener(new com.estimote.sdk.BeaconManager.RangingListener({ - onBeaconsDiscovered: function(region, list){ - var beacons = []; - for (var index = 0; index < list.size(); index++){ - var beacon = list.get(index); - beacons.push({ - proximityUUID : beacon.getProximityUUID().toString(), - rssi : beacon.getRssi(), - major: beacon.getMajor(), - minor: beacon.getMinor(), - measuredPower: beacon.getMeasuredPower() - }); + this.beaconManager.setRangingListener(new com.estimote.sdk.BeaconManager.RangingListener({ + onBeaconsDiscovered: function(region, list){ + var beacons = []; + for (var index = 0; index < list.size(); index++){ + var beacon = list.get(index); + beacons.push({ + proximityUUID : beacon.getProximityUUID().toString(), + rssi : beacon.getRssi(), + major: beacon.getMajor(), + minor: beacon.getMinor(), + measuredPower: beacon.getMeasuredPower(), + proximity: com.estimote.sdk.Utils.computeAccuracy(beacon) + }); + } + _this.callback(beacons); } - _this.callback(beacons); - } - })); - } + })); + } - Estimote.prototype.startRanging = function(data){ - var _this = this; - com.estimote.sdk.SystemRequirementsChecker.check(this.context, new com.estimote.sdk.SystemRequirementsChecker.Callback({ - onRequirementsMissing: function(requirements){ - console.log("Missing perssion(s) " + requirements); + Estimote.prototype.startRanging = function(data){ + var _this = this; + com.estimote.sdk.SystemRequirementsChecker.check(this.context, new com.estimote.sdk.SystemRequirementsChecker.Callback({ + onRequirementsMissing: function(requirements){ + console.log("Missing perssion(s) " + requirements); } - })); + })); - _this.beaconManager.connect(new com.estimote.sdk.BeaconManager.ServiceReadyCallback({ - onServiceReady : function(){ - try { - _this.beaconManager.startRanging(_this.region); - }catch(error){ - console.log(error.message); - } - } - })); - }; + _this.beaconManager.connect(new com.estimote.sdk.BeaconManager.ServiceReadyCallback({ + onServiceReady : function(){ + try { + _this.beaconManager.startRanging(_this.region); + }catch(error){ + console.log(error.message); + } + } + })); + }; - Estimote.prototype.stopRanging = function(){ - if (this.beaconManager != null) { - this.beaconManager.stopRanging(this.region); - } - }; + Estimote.prototype.stopRanging = function(){ + if (this.beaconManager != null) { + this.beaconManager.stopRanging(this.region); + } + }; - return Estimote; + return Estimote; })(); From 09f3da7642eff86cea99e8c084ca036b4166cbee Mon Sep 17 00:00:00 2001 From: Davor Peic Date: Thu, 16 Feb 2017 08:41:31 -0600 Subject: [PATCH 3/4] Fixed iOS library issue ld: library not found for -lEstimoteSDK --- Plugin/platforms/ios/build.xcconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugin/platforms/ios/build.xcconfig b/Plugin/platforms/ios/build.xcconfig index f641392..ff2a8a3 100644 --- a/Plugin/platforms/ios/build.xcconfig +++ b/Plugin/platforms/ios/build.xcconfig @@ -1 +1 @@ -LIBRARY_SEARCH_PATHS = $(SRCROOT)/../../lib/iOS +LIBRARY_SEARCH_PATHS = $(SRCROOT)/../../node_modules/nativescript-estimote-sdk/platforms/ios From 17bbda4f9ca0d4af2848b0e3d6330dcb759f9bc1 Mon Sep 17 00:00:00 2001 From: Davor Peic Date: Thu, 16 Feb 2017 09:25:12 -0600 Subject: [PATCH 4/4] Added example for Angular --- Plugin/README.md | 82 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/Plugin/README.md b/Plugin/README.md index 2448400..31d96a6 100644 --- a/Plugin/README.md +++ b/Plugin/README.md @@ -31,9 +31,11 @@ For Android, add these permissions into app/App_Resources/AndroidManifest.xml - estimote.startRanging - estimote.stopRanging - You can initialize the plugin for a region in the following way: +### Basic example + +``` var Estimote = require('nativescript-estimote-sdk'); var options = { @@ -65,7 +67,85 @@ You can initialize the plugin for a region in the following way: } var estimote = new Estimote(options); +``` + +### Angular Example +items.component.ts +``` +import { Component, OnInit, NgZone } from "@angular/core"; + +var Estimote = require('nativescript-estimote-sdk'); + + +@Component({ + selector: "ns-items", + moduleId: module.id, + templateUrl: "./items.component.html", +}) +export class ItemsComponent implements OnInit { + public items: Array; + + constructor(private zone: NgZone) { + this.items = []; + } + + ngOnInit(): void { + + let options = { + region : 'Progress', // optional + callback : beacons => { + this.zone.run(() => { + + //console.log("My beacons: ", JSON.stringify(beacons)); + + for (var i = 0; i < beacons.length; 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; + } + + this.items.push({ + "proximity" : beacon.proximity, + "identifier": identifier, + "distance": "Distance: " + distance, + "rssi": "Power: " + beacon.rssi + "dBm", + "id": 0 + }); + + } + } + }); + } + } + + var estimote = new Estimote(options); + + estimote.startRanging(); + } + +} + +``` + +items.component.html +``` + + + + + + + +``` # estimote.startRanging