我正在使用Ionic 2和secureStorage插件。问题在于,对于Android,必须使用代码对设备进行保护才能使用安全存储。

在文档中有:

var ss;
var _init = function () {
    ss = new cordova.plugins.SecureStorage(
        function () {
            console.log('OK');
        },
        function () {
            navigator.notification.alert(
                'Please enable the screen lock on your device. This app cannot operate securely without it.',
                function () {
                    ss.secureDevice(
                        function () {
                            _init();
                        },
                        function () {
                            _init();
                        }
                    );
                },
                'Screen lock is disabled'
            );
        },
        'my_app');
};
_init();

但是我不是使用ionic 1,而是使用ionic2。如何调用secureDevice方法?

我做任何类似的事情:
this.secureStorage.create('myStorage')
                .then((storage: SecureStorageObject) => {
                    storage.set('var', 'toto')
                        .then(
                        () => console.log('ok),
                        (e) => console.log('error');
                        );
                }).catch((err) => {
                    console.error('The device is not secured');
                })

我可以在捕获中检测到该设备未固定。但是,如何在console.err旁边添加对secureDevice方法的调用?

文档:https://ionicframework.com/docs/native/secure-storage/

最佳答案

这个问题是raised and fixed,因此您可以使用最新版本的@ionic-native/SecureStorage

如果无法更新 ionic 型原生包装器,请进一步阅读

ionic-native wrapper中似乎没有添加secureDevice函数。

您可能会想到在没有包装的情况下使用cordova插件。

ionic cordova plugin add cordova-plugin-secure-storage --save

在导入之后和类之前,立即声明object。
declare var cordova:any;

并在平台ready()中使用cordova plugin
this.platform.ready().then(() =>{
   this.ss =  new cordova.plugins.SecureStorage(
() => { console.log('Success')},
(error) => {
   console.log('Error ' + error);
   //call here..
   this.ss.secureDevice(()=>{},()=>{});
 },
'myStorage');
});

10-05 20:46
查看更多