2016-02-24 20 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; 
     }; 
    } 
} 
相關問題