Adam
Adam

Reputation: 459

Capacitor not getting Cordova Storage values after upgrade

Version 1 of my app is using Cordova. Version 2 of my app is using Capacitor, but keeping the Cordova Storage and SQLite.

When I upgrade from Version 1 to Version 2, my sqlite data is still there and is handled properly, but my Storage data is not there. If I roll back to the previous version, it finds my Storage data just fine.

A portion of my app.module.ts...

import { IonicStorageModule } from '@ionic/storage-angular';

@NgModule({ declarations: [
        AppComponent,
        SignaturePadComponent,
        SyncProgressBarComponent
    ],
    schemas: [
        CUSTOM_ELEMENTS_SCHEMA
    ],
    bootstrap: [AppComponent], 
    imports: [BrowserModule,
        FormsModule,
        IonicModule.forRoot({
            scrollAssist: true,
            scrollPadding: false
        }),
        IonicStorageModule.forRoot(),

A portion of my app.component.ts...

import { Storage } from '@ionic/storage';

    constructor(
        private platform: Platform,
        private zone: NgZone,
        private router: Router,
        private navCtrl: NavController,
        private toastCtrl: ToastController,
        private alertCtrl: AlertController,
        private storage: Storage
    ) { blah blah   }

    async ngOnInit() {
        // If using a custom driver:
        // await this.storage.defineDriver(MyCustomDriver)
        await this.storage.create();

        this.initializeApp();
    }

public async initializeApp() {
        await this.platform.ready();

        // const options: ConfigureOptions = { group: 'NativeStorage'};
        // Preferences.configure(options);

        this.platform.resume.subscribe(() => {
            this.appInForeground = true;
        });

    const key = await this.storage.get('RegistrationKey');
    }

part of package.json....

"dependencies": {
    "@angular/common": "^19.0.6",
    "@angular/core": "^19.0.6",
    "@angular/forms": "^19.0.6",
    "@angular/platform-browser": "^19.0.6",
    "@angular/platform-browser-dynamic": "^19.0.6",
    "@angular/router": "^19.0.6",
    "@awesome-cordova-plugins/sqlite": "^6.14.0",
    "@azure/msal-angular": "^3.1.0",
    "@azure/msal-browser": "^3.27.0",
    "@capacitor-community/file-opener": "^6.0.1",
    "@capacitor-community/sqlite": "^6.0.2",
    "@capacitor-firebase/messaging": "^6.3.1",
    "@capacitor-mlkit/barcode-scanning": "^7.0.0-next.1",
    "@capacitor/android": "^6.0.0",
    "@capacitor/app": "^6.0.0",
    "@capacitor/app-launcher": "^6.0.3",
    "@capacitor/browser": "^6.0.0",
    "@capacitor/camera": "^6.0.0",
    "@capacitor/core": "^6.0.0",
    "@capacitor/device": "^6.0.0",
    "@capacitor/filesystem": "^6.0.0",
    "@capacitor/geolocation": "^6.0.0",
    "@capacitor/haptics": "^6.0.0",
    "@capacitor/inappbrowser": "^1.0.2",
    "@capacitor/ios": "^6.0.0",
    "@capacitor/keyboard": "^6.0.0",
    "@capacitor/network": "^6.0.0",
    "@capacitor/preferences": "^6.0.0",
    "@capacitor/splash-screen": "^6.0.0",
    "@capacitor/status-bar": "^6.0.0",
    "@capacitor/toast": "^6.0.0",
    "@fortawesome/angular-fontawesome": "^1.0.0",
    "@fortawesome/fontawesome-common-types": "^6.7.1",
    "@fortawesome/fontawesome-pro": "^6.7.1",
    "@fortawesome/fontawesome-svg-core": "^6.7.1",
    "@fortawesome/free-solid-svg-icons": "^6.7.1",
    "@fortawesome/pro-light-svg-icons": "^6.7.1",
    "@ionic/angular": "^8.4.0",
    "@ionic/cordova-builders": "^7.0.0",
    "@ionic/pwa-elements": "^3.2.2",
    "@ionic/storage-angular": "^4.0.0",
    "angularx-qrcode": "^19.0.0",
    "capacitor-blob-writer": "^1.1.17",
    "cordova-sqlite-storage": "^7.0.0",
    "date-fns": "^4.1.0",
    "date-fns-tz": "^3.2.0",
    "firebase": "^11.2.0",
    "ionicons": "^6.0.3",
    "jeep-sqlite": "^2.8.0",
    "moment": "^2.30.1",
    "rxjs": "^7.8.1",
    "signature_pad": "^5.0.4",
    "sql.js": "^1.10.2",
    "tslib": "^2.8.1",
    "zone": "^0.3.4",
    "zone.js": "^0.15.0"
  },
  "devDependencies": {
    "@angular-builders/custom-webpack": "^19.0.0",
    "@angular-devkit/build-angular": "^19.0.7",
    "@angular-eslint/builder": "^18.4.0",
    "@angular-eslint/eslint-plugin": "^18.4.0",
    "@angular-eslint/eslint-plugin-template": "^18.4.0",
    "@angular-eslint/schematics": "^18.4.0",
    "@angular-eslint/template-parser": "^18.4.0",
    "@angular/cli": "^19.0.7",
    "@angular/compiler": "^19.0.6",
    "@angular/compiler-cli": "^19.0.6",
    "@angular/language-service": "^19.0.6",
    "@capacitor/assets": "^3.0.5",
    "@capacitor/cli": "^6.0.0",
    "@eslint/js": "^9.14.0",
    "@ionic/angular-toolkit": "^11.0.1",
    "@types/eslint__js": "^8.42.3",
    "@types/jasmine": "~3.6.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.11.1",
    "@typescript-eslint/eslint-plugin": "^8.13.0",
    "@typescript-eslint/parser": "^8.13.0",
    "capacitor-set-version": "^2.2.0",
    "jasmine-core": "~3.8.0",
    "jasmine-spec-reporter": "~5.0.0",
    "karma": "~6.3.2",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.0.3",
    "karma-coverage-istanbul-reporter": "~3.0.2",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "^1.5.0",
    "protractor": "~7.0.0",
    "ts-node": "^10.9.2",
    "typescript": "^5.5.4",
    "typescript-eslint": "^8.13.0",
    "webpack": "^5.96.1",
    "webpack-cli": "^5.1.4"
  },

The value retrieved from Storage for "RegistrationKey" is always null when running in Version 2, but if I go back to Version 1, it gets the value just fine.

Upvotes: 0

Views: 21

Answers (0)

Related Questions