apla / me.apla.cordova.app-preferences

App preferences plugin for cordova
Apache License 2.0
201 stars 210 forks source link

iOs - Settings seems to get stored and fetched properly in app but not in system preferences. #93

Open ldanet opened 8 years ago

ldanet commented 8 years ago

Hello,

When I store a value, the preferences I see in iOs' Settings app don't change, and when I try to change them in the Settings app, it does not affect the stored value. When I fetch a value I always get the one stored previously from inside my own app. It behaves like my preferences are actually stored somewhere, but not where the Settings app looks for it or saves changes to.

I'm using iOs 9.3.2.

This is my app-settings.json file:

[
    {
        "title":"Debug Mode",
        "type":"toggle",
        "default":false,
        "key":"debug_mode"
    }
]

And this is the code I use:

setDebug: (flag)->
    new Promise (resolve, reject)->
        plugins.appPreferences.store resolve, reject, 'debug_mode', flag

getDebugState: ->
    new Promise (resolve, reject)->
        plugins.appPreferences.fetch resolve, reject, 'debug_mode'

Is there something I am missing?

ldanet commented 8 years ago

After digging some more, I found that my preferences are not stored in the system preferences, but in local storage.

In www/apppreferences.js, here and there there is this piece of code:

if (platform.nativeStore) {
    return platform.nativeStore (resolve, reject, args);
}
return platform.nativeExec (resolve, reject, "AppPreferences", "store", [args]);

platform.nativeStore and platform.nativeFetch are functions that store and fetch preferences in local storage. The last line actually interacts with system preferences, but we never get to it. That means that if the local storage function is available, it will store preferences there, instead of in the system preferences like I expect it to.

Is there a reason for that behavior @apla ? In my opinion the whole point of this plugin is to save the preferences in the system. So that's what it should try first and then maybe fallback to local storage if system preferences aren't available.

shankari commented 7 years ago

@ldanet I noticed similar behavior and filed an issue against my project (https://github.com/e-mission/e-mission-data-collection/issues/88) to investigate further. For me, it is less of an issue to see the preferences in the system preferences, and more that I want to use the value of the preference in native code.

@apla, is there a config option possible, maybe force_native or something?

apla commented 7 years ago

This is completely wrong behavior. I've added test case and removed possible regression. You can try commit 80f060f, seems like it works, but I still working on some features and master can be unstable.

shankari commented 7 years ago

@apla, I will test this next week and update the issue. I see that the commit adds a new test case, but doesn't appear to fix any existing behavior. Did you actually fix the code? Did the tests pass or fail?

apla commented 7 years ago

Regression introduced with pull request and I've fixed it with 2a2a6a2f609d. LocalStorage fallback must be installed only for platforms where it is really needed. For platforms with native part this fallback is not needed.

jmargolese commented 7 years ago

I'm seeing the same problem with the current build. I've verified that my plugin.xml looks like the one in 2a2a6a2 above.

Everything in the app-settings.json gets set correctly, but all settings that I set dynamically from the app only seem to go to localStorage. I can set and fetch them, but they do NOT show up in the simulator's 'Settings' app. (Where I do see the results from app-settings.json)

Is there a way to force the system settings rather than localStorage?

prashu2705 commented 4 years ago

@ldanet @jmargolese @shankari - hi all, hope you all are doing well. I was wondering if this fix got anywhere after the last comment on 12th of May 2017? I'm facing the same problem, only in my case, I want to allow the user to toggle his preferences in settings.app of iOS. Any help is highly appreciated. Thanks.

shankari commented 4 years ago

@prashu2705 I ended up moving on from app preferences and just storing the preferences in an SQLite database. So the user can't use settings.app, but I added some settings into the app directly.

prashu2705 commented 4 years ago

@prashu2705 I ended up moving on from app preferences and just storing the preferences in an SQLite database. So the user can't use settings.app, but I added some settings into the app directly.

Thanks for quick response @shankari . Unfortunately for me I have to use settings.app. I will try and figure out if there's any other lib available or probably try updating this library. @apla - any inputs from you will be highly appreciated.

Thanks.

prashu2705 commented 4 years ago

Hi All, in case anyone wants to use this feature in future, I have managed to implement a fix but submitted a PR on the fork which has fix for Cordova 9 support. here is the PR - https://github.com/NemSavic/me.apla.cordova.app-preferences/pull/5