cordova-plugin-antitampering 的 Ionic 3 实现

Ionic 3 implementation of cordova-plugin-antitampering

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 --save

第二步:使用以下代码调用 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 运行 android

您是否已经尝试过 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);
    });
}]);

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

抱歉,我没有在找到解决方案后立即更新此问题。一百多个浏览量意味着你们中的很多人都遇到过这个问题。基本上,您不必在应用此插件后直接 运行 应用程序。 您需要做的就是为 Android 构建一个 APK 文件,然后将 APK 安装到您的 phone 中。 那是成功处理程序 returns 对象成功的时候,就像这样: { "assets" : { "count" : 135 } } (在我的例子中是 135,计数取决于你得到的文件数量) 这基本上是我的错,我尝试直接 运行 应用程序,而不是先构建 APK,然后将其安装到测试设备上。