简体   繁体   English

未安装LaunchNavigator Ionic2插件

[英]LaunchNavigator Ionic2 plugin is not installed

I am new to Ionic 2 and everything around. 我是Ionic 2的新手和周围的一切。 I'm tryng to setup my first mobile app: touching a button I would open native navigation (Google Maps for Android, for instance). 我正在尝试设置我的第一个移动应用程序:触摸按钮我会打开原生导航(例如Google Maps for Android)。 I've installed launchnavigator plugin: 我已经安装了launchnavigator插件:

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

and inside cremony.ts page: 并在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)
      );
  }
}

make a build npm run build and upload it to IonicView with ionic upload . 进行构建npm run build并使用ionic upload将其上传到IonicView。 I've do everything like suggested in this link but with different luck. 我做了这个链接中提出的所有事情,但运气不同。

But when I click the button (a simple <button ion-button (click)="navigate()">Navigate</button> in the ceremony.html) in the Ionic View an error say: Error launghing navigator: plugin_not_installed . 但是当我在Ionic View中单击按钮(一个简单的<button ion-button (click)="navigate()">Navigate</button> Error launghing navigator: plugin_not_installed中的<button ion-button (click)="navigate()">Navigate</button> )时,出现错误: Error launghing navigator: plugin_not_installed

I inspected the project, the plugins directory contains uk.co.workingedge.phonegap.plugin.launchnavigatorlooks directory. 我检查了项目, plugins目录包含uk.co.workingedge.phonegap.plugin.launchnavigatorlooks目录。 So I look at package.json and config.xml and I've added the value uk.co.workingedge.phonegap.plugin.launchnavigator in the cordovaPlugins and tag <plugin name="uk.co.workingedge.phonegap.plugin.launchnavigator" spec="~3.2.1" /> in the widget root. 所以我查看了package.jsonconfig.xml并在uk.co.workingedge.phonegap.plugin.launchnavigator中添加了值cordovaPlugins并标记了<plugin name="uk.co.workingedge.phonegap.plugin.launchnavigator" spec="~3.2.1" /> widget根目录中的<plugin name="uk.co.workingedge.phonegap.plugin.launchnavigator" spec="~3.2.1" /> npm run build , ionic upload but nothing changed. npm run buildionic upload但没有任何改变。

Where is my error? 我的错误在哪里?

New answer, there is something wrong with your project. 新的答案,您的项目有问题。 Have you modified your index.html file? 你修改过index.html文件了吗? Is it still including cordova.js? 它还包括cordova.js吗? If so what version of Ionic and Cordova are you using? 如果是这样,您使用的是什么版本的Ionic和Cordova?

I made this sample application with your exact code and it works perfectly on both iOS and ANdroid: https://github.com/roblouie/navigator-plugin-test 我使用您的确切代码制作了这个示例应用程序,它在iOS和ANdroid上都运行良好: https//github.com/roblouie/navigator-plugin-test

Did a screen recording on iOS: https://giphy.com/gifs/xTiN0EEQV82aIXWnQI Just grabbed an image on Android, but it works the same: 在iOS上进行了屏幕录制: https//giphy.com/gifs/xTiN0EEQV82aIXWnQI刚刚在Android上抓取了一张图片,但效果相同: Android Pic

Please try the project from github. 请从github尝试该项目。

Cordova plugins need to be called only once platform is ready. 只有在平台准备好后才需要调用Cordova插件。

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

  }

In your function navigate() 在你的函数navigate()

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

The reason for your error is that you are using Ionic View. 您的错误原因是您正在使用Ionic View。 Your Ionic app is just html, css, and javascript. 你的Ionic应用只是html,css和javascript。 However, any plugins you use are written in Java for Android and Objective C for iOS. 但是,您使用的任何插件都是用Java for Android和Objective C for iOS编写的。 That plugin source code is then compiled into your app for each platform. 然后将该插件源代码编译到每个平台的应用程序中。

With Ionic View, it only uploads your app, the html, css, and javascript. 使用Ionic View,它只会上传你的应用程序,html,css和javascript。 Nothing is compiled. 没有编译。 Ionic View is the app itself, and it loads your code. Ionic View是应用程序本身,它会加载您的代码。 So no plugins you have are included. 所以没有包含你自己的插件。 Ionic View itself does have some plugins installed on it, and you can see that list here: https://docs.ionic.io/tools/view/#supported-plugins Ionic View本身安装了一些插件,你可以在这里看到这个列表: https//docs.ionic.io/tools/view/#supported-plugins

Unfortunately you will not be able to test any plugin not in that list without building and deploying to a device or emulator. 遗憾的是,如果不构建和部署到设备或模拟器,您将无法测试不在该列表中的任何插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM