简体   繁体   English

在Ionic 2中使用非离子原生插件

[英]Working with non ionic-native plugins in Ionic 2

I'm using a custom cordova plugin ( https://github.com/VJAI/simple-crypto ), not available in ionic native. 我正在使用自定义cordova插件( https://github.com/VJAI/simple-crypto ),不适用于离子原生。

I'm using Ionic 2 and have installed the plugin using the command: cordova plugin add https://github.com/VJAI/simple-crypto 我正在使用Ionic 2并使用以下命令安装了插件: cordova plugin add https://github.com/VJAI/simple-crypto

The interface is like this: 界面是这样的:

var rncryptor = cordova.require("com.disusered.simplecrypto.SimpleCrypto");

rncryptor.encrypt(key, data, successCallback, failureCallback)
rncryptor.decrypt(key, data, successCallback, failureCallback)`

Method 1: 方法1:
I have tried to invoke the plugin using 我试图使用调用插件

window.plugins.SimpleCrypto.encrypt(...)

But when I run ionic serve , i get the error: 但是当我运行ionic serve ,我得到错误:

TypeError: Cannot read property 'SimpleCrypto' of undefined TypeError:无法读取未定义的属性“SimpleCrypto”

Method 2: 方法2:
Another way i tried was 我试过的另一种方式是

cordova.plugins.SimpleCrypto.encrypt(...)

The error i got was 我得到的错误是

ReferenceError: cordova is not defined ReferenceError:未定义cordova

Is there any way to go around doing this? 有办法绕过这个吗?

Have you tried to use 你试过用吗?

cordova.plugins.SimpleCrypto.encrypt 

function on your device? 您的设备上的功能?

It is working for my case. 它适合我的情况。 The reason being, the emulator is unable to run cordova.js 原因是,模拟器无法运行cordova.js

You could try... 你可以试试......

declare var SimpleCrypto:any;

SimpleCrypto.encrypt(...)

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

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