Skip to content
This repository was archived by the owner on Jan 5, 2021. It is now read-only.

Fix Nativescript 2.5 support to iOS #9

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 89 additions & 2 deletions Plugin/README.md
Original file line number Diff line number Diff line change
@@ -16,25 +16,34 @@ 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
```
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
```

## Methods

- 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 = {
region : 'Progress', // optional
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<any>;

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
```
<ActionBar title="My App" class="action-bar"></ActionBar>
<StackLayout class="page">
<ListView [items]="items" class="list-group">
<template let-item="item">
<Label [nsRouterLink]="['/item', item.id]" [text]="item.identifier"
class="list-group-item"></Label>
</template>
</ListView>
</StackLayout>

```

# estimote.startRanging

101 changes: 51 additions & 50 deletions Plugin/estimote.android.js
Original file line number Diff line number Diff line change
@@ -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;

})();

10 changes: 0 additions & 10 deletions Plugin/platforms/android/AndroidManifest.xml

This file was deleted.

9 changes: 8 additions & 1 deletion Plugin/platforms/android/include.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
android {
productFlavors {
"my-plugin" {
dimension "my-plugin"
}
}
}
dependencies {
compile 'com.estimote:sdk:0.9.4@aar'
}
}
2 changes: 1 addition & 1 deletion Plugin/platforms/ios/build.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
LIBRARY_SEARCH_PATHS = $(SRCROOT)/../../lib/iOS
LIBRARY_SEARCH_PATHS = $(SRCROOT)/../../node_modules/nativescript-estimote-sdk/platforms/ios