我正在尝试将 ibeacon 功能集成到 Ionic 2 应用程序中。
\n\n我正在使用https://ionicframework.com/docs/native/ibeacon/ 插件。
\n\n按照文档中提到的步骤进行操作。
\n\n但是在Android设备上运行该应用程序时,出现错误,
\n\n\n\n\n“导航失败:没有 IBeacon 提供商!”
\n
请提出任何修复建议。
\n\n谢谢。
\n\n信标提供者类:
\n\nimport { Injectable } from \'@angular/core\';\nimport { Platform, Events } from \'ionic-angular\';\nimport { IBeacon } from \'@ionic-native/ibeacon\';\n\n\n\n/*\n Generated class for the BeaconProvider provider.\n// \n See https://angular.io/docs/ts/latest/guide/dependency-injection.html\n for more info on providers and Angular 2 DI.\n*/\n@Injectable()\nexport class BeaconProvider {\n\n delegate: any;\n region: any;\n\n constructor(public platform: Platform, public events: Events, private ibeacon : IBeacon) {\n }\n\n initialise(): any {\n let promise = new Promise((resolve, reject) => {\n // we need to be running on a device\n if (this.platform.is(\'cordova\')) {\n\n // Request permission to use location on iOS\n this.ibeacon.requestAlwaysAuthorization();\n\n // create a new delegate and register it with the native layer\n this.delegate = this.ibeacon.Delegate();\n\n // Subscribe to some of the delegate\xe2\x80\x99s event handlers\n this.delegate.didRangeBeaconsInRegion()\n .subscribe(\n data => {\n this.events.publish(\'didRangeBeaconsInRegion\', data);\n },\n error => console.error()\n );\n\n // setup a beacon region \xe2\x80\x93 CHANGE THIS TO YOUR OWN UUID\n this.region = this.ibeacon.BeaconRegion(\'deskBeacon\', \'E2C56DB5-DFFB-48D2-B060-D0F5A71096E0\');\n\n // start ranging\n this.ibeacon.startRangingBeaconsInRegion(this.region)\n .then(\n () => {\n resolve(true);\n },\n error => {\n console.error(\'Failed to begin monitoring: \', error);\n resolve(false);\n }\n );\n } else {\n console.error(\'This application needs to be running on a device\');\n resolve(false);\n }\n });\n\n return promise;\n }\n\n\n}\nRun Code Online (Sandbox Code Playgroud)\n\n并且在主页中,
\n\nimport { Component } from \'@angular/core\';\nimport { NavController } from \'ionic-angular\';\nimport { AuthService } from \'../../providers/auth-service\';\nimport { LoginPage } from \'../login/login\';\nimport { BeaconProvider } from \'../../providers/beacon-provider\';\nimport { BeaconModel } from \'../../models/beacon-module\';\nimport { Platform, Events } from \'ionic-angular\';\nimport { NgZone } from \'@angular/core\';\n\n@Component({\n selector: \'page-home\',\n templateUrl: \'home.html\',\n providers : [BeaconProvider]\n})\nRun Code Online (Sandbox Code Playgroud)\n
添加
从'@ionic-native/ibeacon'导入{IBeacon};到你的app.module.ts
并将 IBeacon 添加到 app.module.ts 中的提供程序中。
这为我解决了这个问题。
| 归档时间: |
|
| 查看次数: |
1075 次 |
| 最近记录: |