问题
I'm using a custom cordova plugin (https://github.com/VJAI/simple-crypto), not available in ionic native.
I'm using Ionic 2 and have installed the plugin using the command:
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:
I have tried to invoke the plugin using
window.plugins.SimpleCrypto.encrypt(...)
But when I run ionic serve
, i get the error:
TypeError: Cannot read property 'SimpleCrypto' of undefined
Method 2:
Another way i tried was
cordova.plugins.SimpleCrypto.encrypt(...)
The error i got was
ReferenceError: cordova is not defined
Is there any way to go around doing this?
回答1:
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
回答2:
You could try...
declare var SimpleCrypto:any;
SimpleCrypto.encrypt(...)
来源:https://stackoverflow.com/questions/36783081/working-with-non-ionic-native-plugins-in-ionic-2