在Ionic 2中使用非离子原生插件 [英] Working with non ionic-native plugins in Ionic 2

查看:128
本文介绍了在Ionic 2中使用非离子原生插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用自定义cordova插件( https://github.com/VJAI/simple-crypto ),不适用于离子原生。



我正在使用Ionic 2并使用以下命令安装了该插件:
cordova插件添加https://github.com/VJAI/simple-crypto



界面如下:

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

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

方法1:

我试图使用



<$ p $来调用插件p> window.plugins.SimpleCrypto.encrypt(...)

但是当我运行 ionic serve 时,我收到错误:


TypeError:无法读取属性'SimpleCrypto'未定义


方法2:

我尝试的另一种方式是

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

我得到的错误是


ReferenceError:未定义cordova


有什么办法可以解决这个问题吗?

解决方案

您是否尝试过使用

  cordova.plugins.SimpleCrypto.encrypt 

您设备上的功能?



它正在为我的案子工作。原因是,模拟器无法运行cordova.js


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?

解决方案

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

这篇关于在Ionic 2中使用非离子原生插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆