좋아요 :
var __extends = (this && this.__extends) || (function() {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
import { Injectable } from '@angular/core';
import { CordovaInstance, Plugin, CordovaCheck, IonicNativePlugin } from '@ionic-native/core';
/**
* @hidden
*/
var SecureStorageObject = (function() {
function SecureStorageObject(_objectInstance) {
this._objectInstance = _objectInstance;
}
/**
* Gets a stored item
* @param key {string}
* @returns {Promise<string>}
*/
SecureStorageObject.prototype.get = function (key) { return; };
/**
* Stores a value
* @param key {string}
* @param value {string}
* @returns {Promise<any>}
*/
SecureStorageObject.prototype.set = function (key, value) { return; };
/**
* Removes a single stored item
* @param key {string}
* @returns {Promise<string>} returns a promise that resolves with the key that was removed
*/
SecureStorageObject.prototype.remove = function (key) { return; };
/**
* Get all references from the storage.
* @returns {Promise<string[]>} returns a promise that resolves with array of keys storage
*/
SecureStorageObject.prototype.keys = function() { return; };
/**
* Clear all references from the storage.
* @returns {Promise<any>}
*/
SecureStorageObject.prototype.clear = function() { return; };
return SecureStorageObject;
}());
/**
* @hidden
*/
var SecureDeviceObject = (function() {
function SecureDeviceObject(_objectInstance) {
this._objectInstance = _objectInstance;
}
/**
* Brings up the screen-lock settings
* @returns {Promise<any>}
*/
SecureStorageObject.prototype.secureDevice = function() { return; };
return SecureDeviceObject;
}());
export { SecureStorageObject, SecureDeviceObject };
__decorate([
CordovaInstance({
callbackOrder: 'reverse'
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], SecureStorageObject.prototype, "get", null);
__decorate([
CordovaInstance({
callbackOrder: 'reverse'
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, String]),
__metadata("design:returntype", Promise)
], SecureStorageObject.prototype, "set", null);
__decorate([
CordovaInstance({
callbackOrder: 'reverse'
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], SecureStorageObject.prototype, "remove", null);
__decorate([
CordovaInstance({
callbackOrder: 'reverse'
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], SecureStorageObject.prototype, "keys", null);
__decorate([
CordovaInstance({
callbackOrder: 'reverse'
}),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], SecureStorageObject.prototype, "clear", null);
__decorate([
CordovaInstance(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], SecureDeviceObject.prototype, "secureDevice", null);
/**
* @name Secure Storage
* @description
* This plugin gets, sets and removes key,value pairs from a device's secure storage.
*
* Requires Cordova plugin: `cordova-plugin-secure-storage`. For more info, please see the [Cordova Secure Storage docs](https://github.com/Crypho/cordova-plugin-secure-storage).
*
* The browser platform is supported as a mock only. Key/values are stored unencrypted in localStorage.
*
* @usage
*
* ```typescript
* import { SecureStorage, SecureStorageObject } from '@ionic-native/secure-storage';
*
* constructor(private secureStorage: SecureStorage) { }
*
* ...
*
* this.secureStorage.create('my_store_name')
* .then((storage: SecureStorageObject) => {
*
* storage.get('key')
* .then(
* data => console.log(data),
* error => console.log(error)
* );
*
* storage.set('key', 'value')
* .then(
* data => console.log(data),
* error => console.log(error)
* );
*
* storage.remove('key')
* .then(
* data => console.log(data),
* error => console.log(error)
* );
*
* });
*
*
* ```
* @classes
* SecureStorageObject
*/
var SecureStorage = SecureStorage_1 = (function (_super) {
__extends(SecureStorage, _super);
function SecureStorage() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Creates a namespaced storage.
* @param store {string}
* @returns {Promise<SecureStorageObject>}
*/
SecureStorage.prototype.create = function (store) {
return new Promise(function (res, rej) {
var instance = new (SecureStorage_1.getPlugin())(
function() {
res(new SecureStorageObject(instance));
},
function() {
rej(new SecureDeviceObject(instance));
},
store);
});
};
return SecureStorage;
}(IonicNativePlugin));
SecureStorage.decorators = [
{ type: Injectable },
];
/** @nocollapse */
SecureStorage.ctorParameters = function() { return []; };
__decorate([
CordovaCheck(),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], SecureStorage.prototype, "create", null);
SecureStorage = SecureStorage_1 = __decorate([
Plugin({
pluginName: 'SecureStorage',
plugin: 'cordova-plugin-secure-storage',
pluginRef: 'cordova.plugins.SecureStorage',
repo: 'https://github.com/Crypho/cordova-plugin-secure-storage',
platforms: ['Android', 'Browser', 'iOS', 'Windows']
})
], SecureStorage);
export { SecureStorage };
var SecureStorage_1;
//# sourceMappingURL=index.js.map
그러면 사용할 수 있습니다 :
private createSecureStorage() {
this.secureStorageAPI.create(this.storeName).then(
(storage: SecureStorageObject) => {
console.log("secure");
this.secureStorage = storage;
}).catch(
(secureDeviceObject) => {
this.dialogs.alert('Please enable the screen lock on your device. This app cannot operate securely without it.').then(
() => {
// Alert Dismissed, should open the secure lockscreen settings here
secureDeviceObject.secureDevice().then(
() => {
// Try again
console.log("Success");
this.createSecureStorage();
}).catch(() => {
// Try again
console.log(" Error ")
this.createSecureStorage();
})
});
});
}
변경된 기능은 무엇입니까?
내가 한 것은 secureDevice 함수를 SecureDeviceObject라는 새 객체로 이동시키고 데코레이터를 변경하는 것입니다.
__decorate([
CordovaInstance(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], SecureDeviceObject.prototype, "secureDevice", null);
:
var SecureDeviceObject = (function() {
function SecureDeviceObject(_objectInstance) {
this._objectInstance = _objectInstance;
}
/**
* Brings up the screen-lock settings
* @returns {Promise<any>}
*/
SecureStorageObject.prototype.secureDevice = function() { return; };
return SecureDeviceObject;
}());
그런 다음 내가 decorater을 변경했습니다 : 이렇게하면 당신은 GET 호출 등의 기능
이 새로운 객체 인을 설정하려고이 개체를 사용할 수 없습니다
마지막 변화는 거부 약속이 secureDeviceObject를 반환하고 있습니다 :
SecureStorage.prototype.create = function (store) {
return new Promise(function (res, rej) {
var instance = new (SecureStorage_1.getPlugin())(
function() {
res(new SecureStorageObject(instance));
},
function() {
rej(new SecureDeviceObject(instance));
},
store);
});
};
나는이 가정 가능한 최선의 해결책은 아니지만 내가 할 수있는 최선의 방법이었습니다. D android 4에서 8까지 테스트를 통과했습니다.이 모든 작업!
는 올바른 방향으로 날을 가리키는 누군가 :)
감사 @JudgeFudge 희망이 도움
이 하나 도움을 줄 수 없음 하나? 나는 secureDevice()를 호출하기 위해 SecureStorage 객체가 필요하기 때문에 이것이 잘못된 설계라고 생각한다. – Juxture