【问题标题】:LaunchNavigator Ionic2 plugin is not installedLaunchNavigator Ionic2 插件未安装
【发布时间】:2017-02-19 23:52:39
【问题描述】:

我是 Ionic 2 和周围一切的新手。我正在尝试设置我的第一个移动应用程序:触摸一个按钮,我将打开本机导航(例如 Google Maps for Android)。我已经安装了launchnavigator 插件:

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 并使用 ionic upload 将其上传到 IonicView。 我已经按照this link 中的建议做了所有事情,但运气不同。

但是当我在 Ionic View 中单击按钮(一个简单的 <button ion-button (click)="navigate()">Navigate</button> 在仪式.html 中)时,会出现错误提示:Error launghing navigator: plugin_not_installed

我检查了项目,plugins 目录包含uk.co.workingedge.phonegap.plugin.launchnavigatorlooks 目录。所以我查看package.jsonconfig.xml 并在cordovaPlugins 中添加了值uk.co.workingedge.phonegap.plugin.launchnavigator 并在 widget 根中标记 <plugin name="uk.co.workingedge.phonegap.plugin.launchnavigator" spec="~3.2.1" />npm run build, ionic upload 但没有任何改变。

我的错误在哪里?

【问题讨论】:

  • 尝试在this.platform.ready().then(()=>{})内拨打电话
  • 它看起来像 Javascript,而我的代码库在 Typescript 中。有办法把它翻译成 TS 吗?
  • typescript 是 javascript 的超集..
  • 另外,它可以与模拟器一起使用吗?
  • 我知道,但我想要一个连贯的代码库...从未尝试过使用模拟器。

标签: android cordova ionic2


【解决方案1】:

新答案,您的项目有问题。您是否修改了 index.html 文件?它仍然包括cordova.js吗?如果是这样,您使用的是哪个版本的 Ionic 和 Cordova?

我使用您的确切代码制作了这个示例应用程序,它在 iOS 和 Android 上都能完美运行:https://github.com/roblouie/navigator-plugin-test

在 iOS 上进行了屏幕录制:https://giphy.com/gifs/xTiN0EEQV82aIXWnQI 刚刚在 Android 上抓取了一张图片,但它的工作原理相同:

请尝试来自 github 的项目。

【讨论】:

    【解决方案2】:

    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 未定义。
    【解决方案3】:

    您的错误原因是您使用的是 Ionic View。您的 Ionic 应用程序只是 html、css 和 javascript。但是,您使用的任何插件都是用 Java for Android 和 Objective C for iOS 编写的。然后将该插件源代码编译到每个平台的应用程序中。

    使用 Ionic View,它只会上传您的应用、html、css 和 javascript。什么都没有编译。 Ionic View 是应用程序本身,它会加载您的代码。所以没有包含您拥有的插件。 Ionic View 本身确实安装了一些插件,您可以在此处查看该列表:https://docs.ionic.io/tools/view/#supported-plugins

    很遗憾,如果不构建并部署到设备或模拟器,您将无法测试不在该列表中的任何插件。

    【讨论】:

    • 我制作了.apk 包(使用ionic build android 命令),将其安装为不受信任的包(我还没有存储帐户),当我单击按钮时,我得到@987654324 @
    • @marianoc84 好吧,有趣...实际上这有点令人担忧,Cordova 在设备上运行时绝对应该可用。如果在那之前没有其他人解决它,我也许可以在今天晚些时候进一步挖掘。
    猜你喜欢
    • 2017-06-19
    • 2016-05-17
    • 2021-02-23
    • 2018-05-13
    • 1970-01-01
    • 2019-03-23
    • 2019-03-12
    • 2014-10-22
    • 1970-01-01
    相关资源
    最近更新 更多