SecureStorage在离子原生中创建失败

时间:2016-09-20 13:21:06

标签: cordova-plugins ionic2

我正在尝试在离子原生

中使用SecureStorage
let secureStorage: SecureStorage = new SecureStorage();
secureStorage.create('my_store_name')
 .then(
   () => console.log('Storage is ready!'),
   error => console.log(error)
);

但我在iphone 5s上收到错误“undefined is not a constructor (evaluating 'new cordova.plugins.SecureStorage(res, rej, store)')

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我在提供程序中有这个代码,它对我有用......:

...    
public virtual: boolean = true;
    public ss: SecureStorage;

    constructor(
        private _http: Http,
        private _config: ConfigurationService,
        private _events: Events) {
       
        this.virtual = Device.device.isVirtual;
        if (this.virtual !== undefined && !this.virtual) {
            console.log(`Using SecureStorage`); 
            this.ss = new SecureStorage();
            this.ss.create('ss') 
                .then(
                () => {
                    this.virtual = false;
                    this._events.publish('StorageReady'); 
                },
                error => console.log(error)
                );
        } else {
            console.log(`Using localstorage for simulation`); 
            this.virtual = true;
        }
    } ....

希望它有所帮助...