Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ldanet opened this issue May 30, 2016 · 10 comments

Comments

@ldanet
Copy link

ldanet commented May 30, 2016

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
Copy link
Author

ldanet commented Jun 1, 2016

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
Copy link
Contributor

shankari commented Jul 2, 2016

@ldanet I noticed similar behavior and filed an issue against my project (e-mission/e-mission-data-collection#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 added a commit that referenced this issue Jul 10, 2016
@apla
Copy link
Owner

apla commented Jul 10, 2016

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
Copy link
Contributor

@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
Copy link
Owner

apla commented Jul 11, 2016

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

@jmargolese
Copy link

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
Copy link

prashu2705 commented Apr 28, 2020

@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
Copy link
Contributor

@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
Copy link

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants