AppPreferences plugin bug/issue

Hello everyone, I’m developing in Ionic/angular and i was trying to understand the AppPreferences plugin
It kinda worked with a boolean value, but then i tried to store the app language for localization, so with a string.
I’d like to store the device navigator.language as a default value, then use it if the app is newly installed (no settings setted), but i can’t make it work.

I looked into the API and the library. Maybe I’m wrong, but I can’t understand why the store() function says the dict is optional while is the key which is declared as optional, i.e.

* Get a preference value
* @param {string} dict Dictionary for key (OPTIONAL)
* @param {string} key Key
* @return {Promise} Returns a promise
fetch(dict: string, key?: string): Promise;

Same thing in the store() function:

* Set a preference value
* @param {string} dict Dictionary for key (OPTIONAL)
* @param {string} key Key
* @param {any} value Value
* @return {Promise} Returns a promise
store(dict: string, key: string, value?: any): Promise;
Am I wrong or is kinda senseless to store something without a value?

Back to my problem, here’s a sample code for what I was trying to do:

initializeApp(): void {
    this.platform.ready().then(async () => {

      await this.appPreferences.fetch("settings", "defaultLanguage")
        .then(async (inDefLang) => {
          console.log("APP defLang read:", { inDefLang },JSON.stringify(inDefLang));

          if (inDefLang === "") {
            console.log( "defLang is not set => ", { inDefLang },JSON.stringify(inDefLang));
            const toDefLang = navigator.language.slice(0, 2);

            await"preferences", "defaultLanguage", toDefLang)
              .then(async (initDefLang) => {

                await"preferences", "defaultLanguage", toDefLang );
                console.log("Init defLang to",{ toDefLang }, "=>", initDefLang );

                await this.appPreferences .fetch("settings", "defaultLanguage")
                  .then((defLang) => {
                    console.log("APP defLang end:",{ defLang },"=>",JSON.stringify(defLang));
          } else {
            console.log("defLang is set => ", inDefLang);

The rest of the component is working and the imports/modules declarations are working
The output is:

APP defLang read: “”
defLang is not set => “”
Init defLang to {toDefLang: “en”} => OK
APP defLang end: => “”

I tried filling it with async calls but nothing changed
I’m still learning so feel free to criticize if you can


That documentation is for an obsolete version of the framework. If you’re writing new apps, I would highly recommend using modern versions of things, starting here. The plugin you reference is also ancient, as is the Cordova environment it lives in. I would avoid both of them in new apps, which hopefully renders the rest of the discussion moot, because all those asyncs and awaits in what you have posted give me a migraine.

If you are concerned about storing sensitive information, and want to gate it behind the device lockcode, there are other options available, but for something like a default language, I would just use Ionic Storage here. It’s much easier to use, and importantly works in browser environments and on devices with the exact same configuration and client code.

Thank you, I hoped that this plugin was up-to-date and not kinda deprecated
I’ll work with the other, thanks