2017-02-19 85 views
6

我是新來的Ionic 2和周圍的一切。我嘗試設置我的第一個移動應用程序:觸摸按鈕我會打開原生導航(例如Google Maps for Android)。我已經安裝了launchnavigator插件:LaunchNavigator Ionic2插件未安裝

ionic plugin add uk.co.workingedge.phonegap.plugin.launchnavigator 

和cremony.ts頁面內:

import { Component } from '@angular/core'; 
import { NavController } from 'ionic-angular'; 
import { LaunchNavigator, LaunchNavigatorOptions } from 'ionic-native'; 

@Component({ 
    selector: 'page-ceremony', 
    templateUrl: 'ceremony.html' 
}) 
export class Ceremony { 

    constructor(public navCtrl: NavController) { 

    } 

    navigate() { 
    let options: LaunchNavigatorOptions = { 
     start: "" 
    }; 

    LaunchNavigator.navigate("London, UK", options) 
     .then(
     success => alert('Launched navigator'), 
     error => alert('Error launching navigator: ' + error) 
    ); 
    } 
} 

使構建npm run build並將其上傳到IonicView與ionic upload。 我已經盡了一切建議在this link,但運氣不同。

但是當我點擊離子視圖中的按鈕(一個簡單的<button ion-button (click)="navigate()">Navigate</button>)在Ionic View中出錯時說:Error launghing navigator: plugin_not_installed

我檢查過該項目,plugins目錄包含uk.co.workingedge.phonegap.plugin.launchnavigatorlooks目錄。所以我看看package.json和​​3210,並且我在widget根中添加了 中的值uk.co.workingedge.phonegap.plugin.launchnavigator和標記<plugin name="uk.co.workingedge.phonegap.plugin.launchnavigator" spec="~3.2.1" />npm run build,ionic upload但沒有改變。

我的錯誤在哪裏?

+0

嘗試在'this.platform.ready()。內調用' –

+0

它看起來像Javascript,而我的代碼庫位於Typescript中。有一個wya將它轉換爲TS? –

+0

typescript是javascript的超集.. –

回答

1

Cordova插件只需要調用一次platform就緒。

constructor(public navCtrl: NavController,public platform:Platform) {//inject in constructor 

    } 

在你的函數navigate()

this.platform.ready().then(()=>{ 
LaunchNavigator.navigate("London, UK", options) 
     .then(
     success => alert('Launched navigator'), 
     error => alert('Error launching navigator: ' + error) 
    ); 
}); 
+0

沒有改變:( –

+0

@Suraj如果它沒有加載,那麼它會說LaunchNavigator是undefined – Gandhi

1

原因你的錯誤是,你正在使用離子觀。您的離子應用程序只是HTML,CSS和JavaScript。但是,您使用的任何插件都是用Java for Android和Objective C for iOS編寫的。然後,該插件源代碼將被編譯到您的應用程序中用於每個平臺。

隨着離子視圖,它只上傳你的應用程序,html,css和javascript。沒有編譯。離子視圖是應用程序本身,並加載您的代碼。所以沒有插件。離子視圖本身確實安裝了一些插件,你可以在這裏看到這個列表:https://docs.ionic.io/tools/view/#supported-plugins

不幸的是,你不能在沒有構建和部署到設備或模擬器的情況下測試不在列表中的任何插件。

+0

我製作了'.apk'軟件包(使用'ionic build android'命令),將它安裝爲不受信任的軟件包(我還沒有存儲帳戶),當我點擊按鈕時,我得到'錯誤激活導航器: cordova_not_available' –

+0

@ marianoc84好吧,有趣的是,這實際上有點關注,科爾多瓦在設備上運行時一定可用,如果沒有其他人在此之前解決它,我今天晚些時候可能會進一步挖掘。 –

2

新答案,您的項目出現問題。你有沒有修改你的index.html文件?它還包括cordova.js嗎?如果是的話,你使用什麼版本的Ionic和Cordova?

我與你確切的代碼使這個示例應用程序,它完美的作品在iOS和Android版本:0​​

難道iOS上的屏幕記錄:https://giphy.com/gifs/xTiN0EEQV82aIXWnQI 在Android剛拿到的圖像,但它的工作原理是相同的: Android Pic

請嘗試從github項目。 ()=> {})`