我正在尝试加密我的android设备上的文件。然而,在运行代码时,我得到了一个"plugin_not_installed“错误。
我已经使用命令$ ionic cordova plugin add cordova-safe $ npm install --save @I native/file-encryption@4安装了cordova-safe插件
我已经检查了config.xml和package.json中的插件,它确实存在
import { FileEncryption } from '@ionic-native/file-encryption';
constructor(public fileEncryption: FileEncryption){}
this.fileEncryption.encrypt(fileName, AppDefaults.FILEKEY).then(encryptdata=>{
console.log(encryptdata)
})我希望该文件应该被加密,但我得到了一个错误:尝试调用FileEncryption.encrypt,但FileEncryption插件未安装plugin_not_installed
发布于 2020-07-17 15:03:21
错误:
本机:已尝试调用FileEncryption.encrypt,但FileEncryption插件未添加FileEncryption插件:'ionic cordova plugin installed.
Detail
此错误源于'node_modules/@ionic-native/core/decorators/common.js',getPlugin()函数无法检测到cordova-safe或FileEncryption方法,因此请将您的getPlugin()函数替换为此函数
解决方案
从…
export function getPlugin(pluginRef) {
if (typeof window !== 'undefined') {
return get(window, pluginRef);
}
return null;
}至
export function getPlugin(pluginRef) {
if (typeof window !== 'undefined') {
let data = get(window, pluginRef);
let androidAndios = false;
window.Ionic.platforms.forEach(platform => {
if(platform == "android" || platform == "ios" || platform == "hybrid" || platform == "mobile" || platform == "mobile"){
androidAndios = true;
}
});
if(androidAndios){
if(data.safe){
if(data.safe['encrypt'] && data.safe['decrypt']){
return data.safe;
}
}
}
return data;
}
return null;
}https://stackoverflow.com/questions/57492259
复制相似问题