【问题标题】:How to use non native cordova plugins in ionic 4如何在 ionic 4 中使用非原生 cordova 插件
【发布时间】:2019-02-05 04:08:58
【问题描述】:

我正在尝试在我的 Ionic 4 应用程序中使用这个插件: https://github.com/IOCare/cordova-plugin-smartconfig

我使用ionic cordova plugin add https://github.com/IOCare/cordova-plugin-smartconfig.git 安装了插件,它似乎已添加到项目中。 Cordova 插件列表显示:cordova-plugin-smartconfig 1.0.4 "Cordova Smart Config"

我试过了:

declare var espSmartConfig: any; 并使用espSmartConfig.startConfig()

declare var cordova: any; 并使用cordova.plugins.espSmartConfig.startConfig()

declare var window: any; 并使用window.espSmartConfig.startConfig()

..但一切都是未知的。我已经在我的 android 手机上尝试了 Ionic DevApp,在我的 PC 上尝试了 chrome。

我确定我遗漏了一些明显的东西,但我不知道是什么。我发现的所有文档都指的是原生插件。

【问题讨论】:

  • I have tried with Ionic DevApp on my android phone and with chrome on my PC。 Ionic Dev 应用程序是一个预构建的应用程序,仅包含一组精选的 Ionic Native 插件 - 您无法在其中安装 3rd 方插件。 Chrome 是一款浏览器,该插件仅支持原生 Android 和 iOS 平台。要使用它,您必须使用 Cordova 构建自己的原生 Android 应用程序 - see here

标签: cordova ionic-framework cordova-plugins


【解决方案1】:

正如你们中的几个人建议的那样,我尝试构建应用程序并在我的手机上运行它。像魅力一样工作:

declare var espSmartConfig: any;

所以这里的问题只是我用来测试应用程序的工具。

感谢大家的意见!

【讨论】:

  • 就我而言,这个东西在 android 中可以工作,但在 ios 中没有,我正在使用从我的 mac 本地添加的自定义插件
  • @Joonas Lindström 当您执行 espSmartconfig.startConfig 时,是那些 SSID、BSID。等,路由器(又名真正的wifi)或esp32卡(又名接入点wifi)?
  • @Joonas Lindstrom - 这适用于 Android 模拟器还是我需要真正的 Android 设备?此外,移动设备是否有办法获取它所连接的网络的 SSID(就像 ESPTouch 应用程序一样),或者用户是否必须使用此插件手动指定网络的 SSID?
【解决方案2】:
  1. 首先使用添加插件。

cordova 插件添加https://github.com/IOCare/cordova-plugin-smartconfig.git

  1. 然后在 app.ts 中

声明 var espSmartconfig;

  1. 要启动配置,请使用这个。

espSmartconfig.startConfig("ssid", "00:00:00:00","password", "NO", 1, function (res) { }, function (error) {console.log(错误);});

  1. 完成后记得停止配置。

espSmartconfig.stopConfig(function (res) { console.log(res); }, function (error) {console.log(error);});

【讨论】:

  • 听起来 Joonas 已经尝试了大部分,并且在 espSmartconfig.startConfig() 获得了未定义的值。
  • Joonas 你应该在实际的手机上试试这个。只需上传代码并尝试。我正在使用 setTimeout(() => { espSmartconfig.stopConfig(function (res) { console.log(res); }, function (error) {console.log(error);}); }, 5000);用于停止 smartconfig。每次使用后必须停止 smartconfig。我在 5 秒后停止它,以便配置完成,然后停止。希望这会有所帮助
  • app.tsmain.ts 一样吗?
猜你喜欢
  • 1970-01-01
  • 2021-11-30
  • 2017-11-22
  • 2020-06-11
  • 2018-01-01
  • 2018-02-23
  • 2017-07-04
  • 2020-08-29
相关资源
最近更新 更多