【问题标题】:How to open the secure settings of the android phone with my ionic 2 app?如何使用我的 ionic 2 应用程序打开安卓手机的安全设置?
【发布时间】:2017-10-24 16:31:10
【问题描述】:

我正在使用 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,而是ionic 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');
                })

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

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

【问题讨论】:

  • 提出了ionic的问题,以防万一

标签: angular ionic-framework ionic2


【解决方案1】:

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

如果您无法更新 ionic-native 包装器,请进一步阅读

secureDevice 函数似乎没有添加到 ionic-native wrapper 中,尽管它在 cordova plugin 中可用。

可以考虑使用不带包装器的cordova插件。

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

在导入之后和类之前,立即声明对象。

declare var cordova:any;

并在平台 ready() 中使用 the plugin 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');
});

【讨论】:

  • 这个答案会避免这个ERROR Error: Uncaught (in promise): Error: Device is not secure Error: Device is not secure问题
  • @MohanGopi 如果您使用的是安全设备.. 它应该
  • 有什么办法可以避免强制设备锁屏
  • 使用secureStorage 似乎包括屏幕锁定。您可以咨询插件维护者
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-12
  • 1970-01-01
  • 2011-07-20
  • 1970-01-01
  • 1970-01-01
  • 2015-11-09
相关资源
最近更新 更多