Sunday, September 26, 2010

Titanium Titanium.App.Properties problem

Here is another case where in Titanium the iPhone simulator successfully runs a feature that fails on the iPhone. In this case its the Titanium.App.Properties. This is supposed you allow you save global variables. From the documentation, you set it up like this:

Save variable:
Titanium.App.Properties.setString("myVar","myValue");

Retrieve variable:
Titanium.App.Properties.getString("myVar"); '// returns "myValue"

This works fine on the simulator but fails on the iPhone unless you follow two additional steps:

1. From the Kitchen Sink project -- copy /modules/iphone/settings.bundle
2. Create a /modules/iphone folder in your project and paste the settings.bundle file there
3. Make sure to name all your variables with a "_preference" suffix. So our examples above should be:

Save variable:
Titanium.App.Properties.setString("myVar_preference","myValue");

Retrieve variable:
Titanium.App.Properties.getString("myVar_preference"); '// returns "myValue"

No comments: