we are currently developing an app based on Ionic. To enable a new login and to keep the data for a long time, we use ionic storage. In the Android emulation (Android 11) everything seems to work fine. If I install the app on my smartphone (Android 11) my script pops and it breaks off.
The app is an app that returns the next access points for a delivery service. The whole thing works together with a PHP-RestAPI which works with a session. The session as well as access data and other data (the tour) should be saved in the storage. For security the whole AES256 is encrypted (The Values).
Is there a known problem, did I make a mistake?
But there is no active error. So far the problem only occurs on a real device after the bundler.
Here are some code snippets:
app.module.ts
imports: [
IonicModule.forRoot(),
IonicStorageModule.forRoot({
name: '__tourenApp',
driverOrder: ['sqlite', 'indexeddb', 'websql', 'localstorage'],
}),
...
]
Datahandler:
Func-Decrypt:
….
const result = await this.storage.get(key);
if (typeof result !== 'undefined' && result !== '' && result !== null) {
try {
const res: string = await this.aes256.decrypt(this.secureKey, this.secureIV, result);
this.srvUtil.logMessage(`Eintrag '${key}' mit Wert '${res}' entschlüsselt und aus dem lokalem Speicher geholt`);
return res;
} catch (error) {
this.srvUtil.logMessage(`Es konnten keine Daten für den Key '${key}' aus dem Speicher geholt werden`, MessageType.Error);
}
} else {
return '';
}
... Encrypt-Func:
try {
const res = await this.aes256.encrypt(this.secureKey, this.secureIV, value);
await this.storage.set(key, res);
this.srvUtil.logMessage(`Neuen Eintrag '${key}' mit Wert '${value}' verschlüsselt und im lokalem Speicher gesichert`);
} catch (error) {
this.srvUtil.logMessage(
`Fehler beim Setzen eines neuen Storage Eintrags mit dem Key ${key} und dem Wert ${value}`, MessageType.Error);
}
Version details:
- Ionic CLI: 6.12.1
- Ionic Angular: 5.0.0
- Ionic Storage: 2.2.0
- Cordova: 9.0.0
- Angular-Core: 9.0.0
2
Answers
I found the error together with an expert. The error is in the drivers. There is obviously a problem under Cordova with sqlite. For all following therefore the information that it unfortunately only works with the driver variant "localstorage".
This sounds like a bug that was reported. Apparently Ionic Storage doesn’t correctly wait for SQLite to be ready. The proposed workaround is to manually wait for the underlying localForage’s ready event: