I'm using Ionic 2 and the secureStorage plugin. The problem is that with Android, the device has to be secured with a code to use secure storage.
In the documentation it has:
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();
But I'm not using ionic 1 but ionic 2. How to call the secureDevice method?
I do anything like:
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');
})
I can detect in the catch that the device is not secured. But how can I add next to my console.err a call to the secureDevice method?
The documentation: https://ionicframework.com/docs/native/secure-storage/
To run your app, all you have to do is enable USB debugging and Developer Mode on your Android device, then run ionic cordova run android --device from the command line. Enabling USB debugging and Developer Mode can vary between devices, but is easy to look up with a Google search.
Don't have a Secure Storage subscription? Try it free now.
Ionic is an HTML5 mobile app development framework targeted at building hybrid mobile apps. Hybrid apps are essentially small websites running in a browser shell in an app that have access to the native platform layer.
This issue was raised and fixed so you can use the latest version of @ionic-native/SecureStorage
.
If you are unable to update the ionic-native wrapper, read further.
secureDevice
function doesnt seem to be added in the ionic-native wrapper though its available in the cordova plugin.
You could think of using the cordova plugin without the wrapper.
ionic cordova plugin add cordova-plugin-secure-storage --save
Immediately after the imports and before the class, declare the object .
declare var cordova:any;
And use the plugin api within platform ready().
this.platform.ready().then(() =>{
this.ss = new cordova.plugins.SecureStorage(
() => { console.log('Success')},
(error) => {
console.log('Error ' + error);
//call here..
this.ss.secureDevice(()=>{},()=>{});
},
'myStorage');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With