1. #1
    Sencha User
    Join Date
    Apr 2012
    Posts
    49
    Answers
    2
    Vote Rating
    3
    svendahlstrand is on a distinguished road

      1  

    Default Answered: Best practices to save user settings locally

    Answered: Best practices to save user settings locally


    Hello!

    Are there best practices when storing user settings locally in Sencha Touch? Example:

    A simple, one user, app where the user can change some settings - like background color, text size etcetera.

    Use case:
    • The user navigates to the settings view
    • The user changes some settings in an ordinary form
    • The user clicks save and the settings are persisted
    So I would like to use local storage for this. Can I use the model layer with a LocalStorage proxy? The way I see it, there's only one Settings object: a singleton. How do I handle that?

    Thanks!

  2. you can check the count of the store and work with a record with the same ID, should be only one record in the store. so if no record exist create one otherwise work with the existing one

  3. #2
    Sencha - Training Team mrsunshine's Avatar
    Join Date
    Sep 2008
    Location
    Germany - Darmstadt
    Posts
    690
    Answers
    21
    Vote Rating
    12
    mrsunshine will become famous soon enough

      1  

    Default


    yes, the easiest way is to create a settings model and store it in the localstorage

  4. #3
    Sencha User
    Join Date
    Apr 2012
    Posts
    49
    Answers
    2
    Vote Rating
    3
    svendahlstrand is on a distinguished road

      0  

    Default


    How do I make sure that theres only one settings object persisted?

  5. #4
    Sencha - Training Team mrsunshine's Avatar
    Join Date
    Sep 2008
    Location
    Germany - Darmstadt
    Posts
    690
    Answers
    21
    Vote Rating
    12
    mrsunshine will become famous soon enough

      1  

    Default


    you can check the count of the store and work with a record with the same ID, should be only one record in the store. so if no record exist create one otherwise work with the existing one

  6. #5
    Sencha User
    Join Date
    Apr 2012
    Posts
    19
    Answers
    1
    Vote Rating
    0
    Ageris is on a distinguished road

      0  

    Default


    Before you put too much effort into using localstorage you should read this:

    http://www.softwareindustryinsights.com/2012/04/building-hybrid-apps-important-change-in-ios-5-1/

    Basically what it means is that the localstorage for WebViews (like phonegap and sencha) is now treated as a temporary store that can be cleared at any time by the OS. So do not trust it to remain after you application is closed.

  7. #6
    Sencha User
    Join Date
    Apr 2012
    Posts
    49
    Answers
    2
    Vote Rating
    3
    svendahlstrand is on a distinguished road

      0  

    Default


    Ok, the manual way then. I thought that maybe there is a function to save user settings through the framework. But now I now it doesn't. Thank you!

  8. #7
    Sencha User
    Join Date
    Apr 2012
    Posts
    49
    Answers
    2
    Vote Rating
    3
    svendahlstrand is on a distinguished road

      0  

    Default


    Quote Originally Posted by Ageris View Post
    Basically what it means is that the localstorage for WebViews (like phonegap and sencha) is now treated as a temporary store that can be cleared at any time by the OS. So do not trust it to remain after you application is closed.
    Yeah I read about that in the Sencha blog. But if I understand it correctly theres no problem if my users add the app through Safari to the home screen?

  9. #8
    Sencha User
    Join Date
    Apr 2012
    Posts
    19
    Answers
    1
    Vote Rating
    0
    Ageris is on a distinguished road

      0  

    Default


    I don't think so. The way I understood it is that localstorage is now stored under a "temporary" folder on the device regardless of its origin (WebView or home screen). This means that if the space is needed by some other application or website your data may be deleted. The spec unfortunately says little about persistence, but I seem to remember reading somewhere that Chrome will purge unused data if the space is needed. I may be wrong though.

  10. #9
    Sencha User
    Join Date
    Mar 2012
    Posts
    36
    Vote Rating
    0
    flyingace is on a distinguished road

      0  

    Default


    By my understanding this doesn't totally rule out the use of localStorage. Phonegap 1.6 has come up with a solution whereby the location that localStorage records are kept is moved to a location that won't be deleted/cleaned up.

  11. #10
    Sencha User
    Join Date
    Apr 2012
    Posts
    19
    Answers
    1
    Vote Rating
    0
    Ageris is on a distinguished road

      0  

    Default


    Yeah, but PhoneGap has done something actively to fix the issue. I think they move the localstorage file back to its old location or something like that. Sencha does not do that yet as far as I know. So if you are packaging with PhoneGap you should be OK, but using plain Sencha Touch will probably not work.