anu*_*bis 7 ionic-framework ionic2 angular
我正在使用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();
Run Code Online (Sandbox Code Playgroud)
但我不是使用离子1而是离子2.如何调用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');
})
Run Code Online (Sandbox Code Playgroud)
我可以在捕获中检测到设备没有安全.但是如何在我的console.err旁边添加一个对secureDevice方法的调用?
此问题已提出并修复,因此您可以使用最新版本的@ionic-native/SecureStorage.
如果您无法更新离子原生包装,请进一步阅读.
secureDevice功能似乎没有添加到离子原生包装中,尽管它在cordova插件中可用.
您可以考虑在没有包装的情况下使用cordova插件.
ionic cordova plugin add cordova-plugin-secure-storage --save
Run Code Online (Sandbox Code Playgroud)
在导入之后和类之前,立即声明该对象.
declare var cordova:any;
Run Code Online (Sandbox Code Playgroud)
并在platform ready()中使用插件api.
this.platform.ready().then(() =>{
this.ss = new cordova.plugins.SecureStorage(
() => { console.log('Success')},
(error) => {
console.log('Error ' + error);
//call here..
this.ss.secureDevice(()=>{},()=>{});
},
'myStorage');
});
Run Code Online (Sandbox Code Playgroud)