Search code examples
iostitaniumnsuserdefaultstitanium-mobile

Save data to NSUserDefaults using Titanium


I'm currently working on a Titanium based iOS application.

In which I need to save some data (A progress value) to NSUserDefaults.

I had done this in iOS but don't know how to do this using Titanium, I have searched a lot for doing this in Titanium, but couldn't find any solution.

I just need to store this single value, so no need of using a sqlite database, that's why I'm opting NSUserDefaults.

Please help me, Thanks in advance.


Solution

  • I found a solution.

    The App Properties module is used for storing application-related data in property/value pairs that persist beyond application sessions and device power cycles.

    Storing data:

    Ti.App.Properties.setString('myName', 'Midhun');
    

    Retrieving data:

    var name = Ti.App.Properties.getString('myName'));
    

    I don't know whether it saves the data to NSUserDefaults, anyway it fixed my issue.

    Reference : Titanium.App.Properties.