Ionic 2アプリでイベコン機能を統合しようとしています。Ionic 2では、iBeaconインテグレーションで「IBeaconのプロバイダがありません」というエラーが発生しました
私はhttps://ionicframework.com/docs/native/ibeacon/プラグインを使用しています。
この文書に記載されている手順に従います。
- プロバイダークラスを作成しました。
- プラグインの統合が追加されました。
- [ホーム]ページでプロバイダクラスを呼び出します。
しかし、Androidデバイス上でアプリケーションを実行、エラーを取得し、
は "移動しないために失敗しました:!IBeacon用ませプロバイダを"
修正をお願いいたします。
ありがとうございました。
ビーコンProviderクラス:
import { Injectable } from '@angular/core';
import { Platform, Events } from 'ionic-angular';
import { IBeacon } from '@ionic-native/ibeacon';
/*
Generated class for the BeaconProvider provider.
//
See https://angular.io/docs/ts/latest/guide/dependency-injection.html
for more info on providers and Angular 2 DI.
*/
@Injectable()
export class BeaconProvider {
delegate: any;
region: any;
constructor(public platform: Platform, public events: Events, private ibeacon : IBeacon) {
}
initialise(): any {
let promise = new Promise((resolve, reject) => {
// we need to be running on a device
if (this.platform.is('cordova')) {
// Request permission to use location on iOS
this.ibeacon.requestAlwaysAuthorization();
// create a new delegate and register it with the native layer
this.delegate = this.ibeacon.Delegate();
// Subscribe to some of the delegate’s event handlers
this.delegate.didRangeBeaconsInRegion()
.subscribe(
data => {
this.events.publish('didRangeBeaconsInRegion', data);
},
error => console.error()
);
// setup a beacon region – CHANGE THIS TO YOUR OWN UUID
this.region = this.ibeacon.BeaconRegion('deskBeacon', 'E2C56DB5-DFFB-48D2-B060-D0F5A71096E0');
// start ranging
this.ibeacon.startRangingBeaconsInRegion(this.region)
.then(
() => {
resolve(true);
},
error => {
console.error('Failed to begin monitoring: ', error);
resolve(false);
}
);
} else {
console.error('This application needs to be running on a device');
resolve(false);
}
});
return promise;
}
}
、ホームページで
は、import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { AuthService } from '../../providers/auth-service';
import { LoginPage } from '../login/login';
import { BeaconProvider } from '../../providers/beacon-provider';
import { BeaconModel } from '../../models/beacon-module';
import { Platform, Events } from 'ionic-angular';
import { NgZone } from '@angular/core';
@Component({
selector: 'page-home',
templateUrl: 'home.html',
providers : [BeaconProvider]
})
よう
provider
リストの下app.module.ts
にIBeacon定義を入れて、私はお勧め'プロバイダー:HomePageの[InvokedProvider]'? –
関連コードを投稿してください。誰もそれなしでは誰も気付くことはできません。:) –
@SagarKulkarniはいプロバイダが追加されました。 – Basheer