Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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?

like image 991
Huiting Avatar asked Apr 22 '16 01:04

Huiting


1 Answers

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

like image 176
Gene Avatar answered Nov 07 '22 14:11

Gene