home.ts
import {ChangeDetectorRef, Component} from '@angular/core';
import { Platform} from 'ionic-angular';
import {IBeacon} from "@ionic-native/ibeacon";
import {isBoolean} from "ionic-angular/util/util";
import {AndroidPermissions} from "@ionic-native/android-
permissions/ngx";
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
homePage: string =null;
outputdata: any;
outputerror: any;
inputdata: any;
inputerror: any;
beaconData: any;
advertinputdata: any;
advertavailinputerror: any;
buke: any;
auther: any;
bule: any;
pero: any;
constructor(public change: ChangeDetectorRef,
public platform: Platform,
private ibeacon: IBeacon,
private androidPermissions: AndroidPermissions) {
this.homePage = "1000";
}
watch() {
this.androidPermissions.requestPermission(this.androidPermissions.PERMISSION.ACCESS_COARSE_LOCATION).then(
data => this.pero = data,
error => console.log(error)
)
this.ibeacon.enableBluetooth().then(
data => this.auther = data,
error => console.log(error)
)
this.ibeacon.getAuthorizationStatus().then(
data => this.auther = data.authorizationStatus,
error => console.log(error)
)
this.ibeacon.isBluetoothEnabled().then(
()=> this.buke = isBoolean(this.ibeacon.isBluetoothEnabled()),
error => console.log(error)
)
this.ibeacon.startAdvertising(this.ibeacon.BeaconRegion('deskBeacon', '7813eab4-9ee5-447b-b3ee-6179c9b9877a', 10, 10, true), -59).then(
data => this.inputdata = data,//"yay!" + console.log("yay! task done"),
error => console.log(error)
)
this.ibeacon.isAdvertising().then(
() => this.advertinputdata = isBoolean(this.ibeacon.isAdvertising()) ,
error => console.log(error)
)
}
monitor(){
this.platform.ready().then(()=>{
// Request permission to use location on iOS
this.ibeacon.requestAlwaysAuthorization();
// create a new delegate and register it with the native layer
let delegate = this.ibeacon.Delegate();
// Subscribe to some of the delegate's event handlers
delegate.didRangeBeaconsInRegion()
.subscribe(
data => this.outputdata = data,
error => console.error()
);
delegate.didStartMonitoringForRegion()
.subscribe(
data => console.log('didStartMonitoringForRegion: ', data),
error => console.error()
);
delegate.didEnterRegion()
.subscribe(
data => {
console.log('didEnterRegion: ', data);
}
);
let beaconRegion = this.ibeacon.BeaconRegion('deskBeacon','7813eab4-9ee5-447b-b3ee-6179c9b9877a');
this.ibeacon.startMonitoringForRegion(beaconRegion)
.then(
() => console.log('Native layer received the request to monitoring'),
error => console.error('Native layer failed to begin monitoring: ', error)
);
})
}
}
home. html
<ion-header>
<ion-navbar color="primary">
<ion-title>
Test
</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<div *ngIf="!beaconData; else beaconFound">
<ion-card>
<ion-card-header>
Start Scan
</ion-card-header>
<ion-card-content>
<p>Click the start button to scan for beacons</p>
<button ion-button (click)="monitor()">Scan</button>
<p>beacon data = {{outputdata}}</p>
<p>Error = {{outputerror}}</p>
</ion-card-content>
</ion-card>
</div>
<div>
<ion-card>
<ion-card-header>
Start Scan
</ion-card-header>
<ion-card-content>
<p>Click the start button to scan for beacons</p>
<button ion-button (click)="watch()">Transmit</button>
<p>Bluetooth - {{buke}}</p>
<p>permission - {{pero}}</p>
<p>Bluetooth-enable - {{bule}}</p>
<p>getauth - {{auther}}</p>
<p>Success-advertising = {{inputdata}}</p>
<p>Error = {{inputerror}}</p>
<p>Success = {{advertinputdata}}</p>
<p>advertavail - {{advertavailinputerror}}</p>
</ion-card-content>
</ion-card>
</div>
<ng-template #beaconFound>
<ion-card>
<ion-card-header>
Becon Data
</ion-card-header>
<ion-card-content>
<p>Yay!</p>
<ion-list>
<ion-item>{{beaconData.address}}</ion-item>
<ion-item>{{beaconData.txPower}}</ion-item>
<ion-item>{{beaconData.temperature}}</ion-item>
</ion-list>
<a [href]="beaconData.url" ]>URl</a>
</ion-card-content>
</ion-card>
</ng-template>
</ion-content>
Я столкнулся с другой проблемой, которая также указана под выводом, который я получаю это:
.isAdvertising() = false
.isBluetoothEnabled() =false
.getAuthorizationStatus() = authorised
.startAdvertising()= its not advertising
плюс, когда я пытался использовать eddystone evothing после добавления плагина, рекламный код не работает, так как сам загруженный код плагина не имеет функции startadvertising, но в сети, где я вижу его исходный код присутствует