【问题标题】:Cordova InAppBrowser plugin is not installed未安装 Cordova InAppBrowser 插件
【发布时间】:2018-04-17 04:59:21
【问题描述】:

当我列出插件 (cordova plugin list) 时,它会列在那里,但是当我在 android 设备上运行我的代码时,我会在控制台中收到此消息(来自 chrome 远程调试器): Native: InAppBrowser is not installed or you are running on a browser. Falling back to window.open, all instance methods will NOT work.

我有最新版本的 ionic-cli。

我在这里包含了一个示例项目:https://github.com/golear91/ionic2-broken-inappbrowser

我基本上:

  • 使用 cli“启动”选项卡项目
  • 添加了一个提供者(使用生成器)
  • 将提供程序添加到我的一个标签中
  • cordova plugin add cordova-plugin-inappbrowser
  • 导入并尝试使用InAppBrowser

我尝试使用插件删除并重新安装无济于事。

有什么错误的想法吗?

【问题讨论】:

  • 好吧,请记住这不是错误。它只是一个警告,告诉它可能无法在浏览器中工作。就这样吧。
  • 我知道它在浏览器中不起作用,但是我正在安卓设备上对其进行测试,所以它不应该吐出这条消息。 (实际上提到的实例方法不起作用,我需要它们,这就是我问这个问题的原因)。我之前已经让它工作而没有吐出错误,但我不知道这次我做错了什么。

标签: angular typescript ionic2


【解决方案1】:

离子原生插件的使用必须等待设备“准备好”

对于带有 Angular 的 Ionic2,这可以通过将 Platform(以及其他所有东西)导入您计划使用 ionic-native 插件的任何组件/服务来实现。

import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';
import { InAppBrowser } from 'ionic-native';
import { Platform } from 'ionic-angular';

然后在准备好的平台上等待:

@Injectable()
export class Service() {
   constructor(public platform: Platform) {
     this.init()
   }
   init() {
     this.platform.ready().then(() => {
       let browser = new InAppBrowser('https://ionic.io', '_system');
       browser.on("loadstop").subscribe(()=> console.log("loadstop"));
     });
   }
}

【讨论】:

  • 但是在哪里添加此代码?改进您对如何执行此操作的答案
  • @AlokRajasukumaran 您必须将平台导入到您想要使用离子原生插件的任何组件/服务(添加到答案中)。
【解决方案2】:

添加 plugins/android.json 和 plugins/ios.json

"cordova-plugin-inappbrowser": {}

这对我有用。

希望能帮到你。

问候。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-04
    • 2018-08-31
    • 2019-05-14
    相关资源
    最近更新 更多