科尔多瓦插件抗干扰的Ionic 3实现

时间:2019-03-15 05:39:38

标签: cordova ionic-framework ionic3

https://www.npmjs.com/package/cordova-plugin-antitampering

有人在他们的项目中实现了此插件吗? 我已经实现了插件,但是调用了此函数:

window.cordova.plugins.AntiTampering.verify(
    function (success) {
        console.info(success);
        // {“assets”: {“count”: x}} - where x is the number of assets checked
    },
    function (error) {
        console.error(error);
        // gives you the file on which tampering was detected
    }
);

问题是,该函数进入成功块,但计数为0,这意味着该插件实际上并未扫描任何文件。我想知道怎么了。

提到我所遵循的步骤:

第一步:使用cmd安装。 命令是: cordova插件添加cordova-plugin-antitampering --variable ENABLE_CORDOVA_CALLBACK = true-保存

第二步:使用以下代码在app.component.ts中调用方法:

declare var window: any;

constructor(){
    this.checkTampering();
}  

checkTampering(){
    alert(“Inside Check Tampering”);
    try {
        alert("Inside Try: ");
        window.cordova.plugins.AntiTampering.verify(
            function (success) {
                alert(JSON.stringify(success));
                // {“assets”: {“count”: x}} - where x is                 the number of assets checked
            },
            function (error) {
                alert(JSON.stringify(error));
                // gives you the file on which tampering was detected
            }
        );
    } catch (e) {
        alert("Caught some exception when implementing Integrity check: " + JSON.stringify(e));
    }
}

第3步:使用以下命令在设备上运行:ionic cordova run android

2 个答案:

答案 0 :(得分:1)

很抱歉,找到解决方案后,我没有立即更新此问题。一百多个视图意味着很多人都面临这个问题。基本上,您无需在应用此插件后直接运行应用程序。 您需要做的就是,为Android生成一个APK文件,然后在您的手机中安装APK。 那就是成功处理程序返回对象成功的方式,如下所示: {“资产”:{“计数”:135}} (在我的情况下为135,具体取决于您获得的文件数) 基本上是我的错,我尝试直接运行该应用程序而不是先构建一个APK,然后再将其安装在测试设备上。

答案 1 :(得分:0)

您是否继续尝试了Angular的实现?

var app = angular.module('myApproximatelySecureApp', ['duddu.antitampering']);

app.run(['$antitampering', function ($antitampering) {
    $antitampering.verify().then(function (success) {
        console.info(success);
    }, function (error) {
        console.error(error);
    });
}]);

试一试,看看成功的结果是什么。