简体   繁体   English

Cordova 插件不适用于 Capacitor

[英]Cordova plugins not working with Capacitor

I'm not sure how to get Cordova plugins working with Ionic 4 + Capacitor in Android Emulator.我不确定如何让 Cordova 插件与 Android Emulator 中的 Ionic 4 + Capacitor 一起使用。

I am following this example ( https://ionicacademy.com/create-pdf-files-ionic-pdfmake/ ) but I am going to add some Capacitor plugins to it in order to use the camera to add images.我正在关注这个例子( https://ionicacademy.com/create-pdf-files-ionic-pdfmake/ ),但我将向其中添加一些电容器插件,以便使用相机添加图像。

Do the Cordova plugins below still work with Capacitor?下面的 Cordova 插件是否仍然适用于 Capacitor? I can't get them to work at all.我根本无法让他们工作。 They work fine using cordova rather than Capacitor.他们使用cordova而不是Capacitor可以正常工作。 I have created project as follows:我创建的项目如下:

ionic start myApp
cd myApp
npm install @capacitor/core @capacitor/cli
npx cap init
npm install pdfmake @ionic-native/file-opener @ionic-native/file 
npm install cordova-plugin-file-opener2
npm install cordova-plugin-file

*Writes code*

create myApp/www dir
copied index.html to myApp/www dir
npx cap add android
npx cap update
npx cap open android (opens android studio)
ionic capacitor run android
npx cap sync
npx cap copy
run in emulator from android studio

Expected Result:预期结果:

pdf is saved to device and is then opened. pdf 保存到设备,然后打开。

Actual result:实际结果:

No warnings or errors in console.控制台中没有警告或错误。
Fails on this on line and does not proceed:在线失败并且不继续:

this.file.writeFile(this.file.dataDirectory, 'myletter.pdf', blob, { replace: true }).then(fileEntry => {

Update: Warnings and error resolved but still not working更新:警告和错误已解决但仍无法正常工作

Be sure to run npx cap sync after installing your cordova plugins:安装cordova插件后,请务必运行npx cap sync

https://capacitor.ionicframework.com/docs/basics/cordova https://capacitor.ionicframework.com/docs/basics/cordova

Just in case anyone is having an issue with the file plugin in capacitor and comes across this post like I did以防万一有人对电容器中的文件插件有问题,并像我一样看到这篇文章

Capacitor comes with it's own filing library that's pretty easy to use. Capacitor 带有自己的归档库,非常易于使用。 If you're building a capacitor app and need to write and read files I'd recommend using this如果您正在构建电容器应用程序并需要写入和读取文件,我建议您使用它

https://capacitor.ionicframework.com/docs/apis/filesystem/ https://capacitor.ionicframework.com/docs/apis/filesystem/

试试这个命令

ionic integrations disable capacitor

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

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