LaunchNavigator Ionic2插件未安装
我是新来的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
但没有改变。
我的错误在哪里?
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)
);
});
没有改变:( –
@Suraj如果它没有加载,那么它会说LaunchNavigator是undefined – Gandhi
原因你的错误是,你正在使用离子观。您的离子应用程序只是HTML,CSS和JavaScript。但是,您使用的任何插件都是用Java for Android和Objective C for iOS编写的。然后,该插件源代码将被编译到您的应用程序中用于每个平台。
随着离子视图,它只上传你的应用程序,html,css和javascript。没有编译。离子视图是应用程序本身,并加载您的代码。所以没有插件。离子视图本身确实安装了一些插件,你可以在这里看到这个列表:https://docs.ionic.io/tools/view/#supported-plugins
不幸的是,你不能在没有构建和部署到设备或模拟器的情况下测试不在列表中的任何插件。
我制作了'.apk'软件包(使用'ionic build android'命令),将它安装为不受信任的软件包(我还没有存储帐户),当我点击按钮时,我得到'错误激活导航器: cordova_not_available' –
@ marianoc84好吧,有趣的是,这实际上有点关注,科尔多瓦在设备上运行时一定可用,如果没有其他人在此之前解决它,我今天晚些时候可能会进一步挖掘。 –
新答案,您的项目出现问题。你有没有修改你的index.html文件?它还包括cordova.js吗?如果是的话,你使用什么版本的Ionic和Cordova?
我与你确切的代码使这个示例应用程序,它完美的作品在iOS和Android版本:0
难道iOS上的屏幕记录:https://giphy.com/gifs/xTiN0EEQV82aIXWnQI 在Android刚拿到的图像,但它的工作原理是相同的:
请尝试从github项目。 ()=> {})`
尝试在'this.platform.ready()。内调用' –
它看起来像Javascript,而我的代码库位于Typescript中。有一个wya将它转换为TS? –
typescript是javascript的超集.. –