diff --git a/Plugin/README.md b/Plugin/README.md
index d1a36ff..31d96a6 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
@@ -24,9 +31,11 @@ tns plugin add nativescript-estimote-sdk
- 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 = {
@@ -34,7 +43,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";
@@ -58,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
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;
})();
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
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