2016-02-24 22 views
1

我是ionic framework的新手,AngularJS。我已使用Ionic ver2(使用AngularJS2)开始学习和开发Ionic framework如何在ionic2应用程序中使用iBeacon?

我想知道,如何在Ionic2中使用外部库?像使用cordova iBeacon,cordova iBeacon docs

如何构建我的应用程序,这样我可以写使用外部库的一个或多个通用的功能(像cordov iBeacon显示),并在我的应用程序在以往任何时候,我需要(就像在不同的页面JS)使用它。

或者 - 如何包含执行本机硬件相关操作所需的库?

随时提供您的所有想法和建议。

很多很多,谢谢。

+0

请不要共享如果您有任何文章或与该主题相关的文档。 – Dipak

回答

6

最后,我能够自己弄清楚所有。

步骤1:添加插件到应用程序

通过移动到项目文件夹通过命令行,运行命令的下面的行向插件添加到项目

sudo cordova plugin add https://github.com/petermetz/cordova-plugin-ibeacon.git

第2步:在应用程序中使用该插件

确保在plugins/fetch.json插件的细节补充:

"com.unarin.cordova.beacon": { 
     "source": { 
      "type": "git", 
      "url": "https://github.com/petermetz/cordova-plugin-ibeacon.git", 
      "subdir": "." 
     }, 
     "is_top_level": true, 
     "variables": {} 
    } 

而在plugins/android.jsoninstalled_plugins以下行都是存在的,

"com.unarin.cordova.beacon": { 
      "PACKAGE_NAME": "io.ionic.starter" 
     } 

这它,我们开始使用应用程序中任何页面的插件功能,通过使用变量:cordova.plugins.locationManager

使用范例:

要启用蓝牙设备:cordova.plugins.locationManager.enableBluetooth();

注意 如果没有工作的罚款,再次更新插件。首先更新cordova-plugin-ibeaconremoved该应用程序的插件和added again

+0

谢谢迪帕克..你节省了我的时间。 – user1685442

+0

很高兴知道有人遇到这个问题。欢迎。 :) – Dipak

+0

是的,但如何进口离子原生? '从'离子本土'导入{cordovaBeacon};'这有可能吗? – user2617214

-2
export class UserPage {constructor(authservice, navcontroller) { 
     this.service = authservice; 
     this.nav = navcontroller; 
     this.distance = 0;  
    } 
    getDistance(){ 
     delegate.didRangeBeaconsInRegion = function (pluginResult) { 
       this.distance=pluginResult.beacons[0].rssi; 
     }; 
    } 
} 
相关问题