From The Blog: Introducing new preference storage features

This is a lovely feature. I really liked the loadsave module, but this is easier to use.

I can’t seem to understand how to dump all the keys like you do funkyvisions  :unsure:

@sirmania, @funkyfishions executed a command line command through the Mac’s “terminal” app that gives you access to the operating system’s command line.

“defaults” is the command that lets you manage user preferences on the Mac. For your simulator run versions of your apps, all of your preferences are stored in the com.coronalabs.Corona_Simulator preferences. To keep each of your simulator apps apart we generate a string similar to “82e60786ad31b97d35a0e9d48af094b4” but it will be different for each app. From the simulator you can load your app, and look in the console log window that we open and look for a line like this:

Oct 09 12:01:45.509 Project sandbox folder: ~/Library/Application Support/Corona Simulator/TurkeysRevenge- 1A1B9255FFAB34A09DDEB391EBF1CD9B

where it tells you the sandbox folder. That long number is your per-app ID that you can use to look up your keys. However that string has all the letters uppercased, but in the defaults they are lowercased. Never fear a simple change in the command will work for you without having to retype everything in lower case:

defaults read com.coronalabs.Corona_Simulator | grep -i 1A1B9255FFAB34A09DDEB391EBF1CD9B

 

The | command says to take the output from the first command and make it the input of the second command. The “grep” command is basically a search command and will filter out anything that doesn’t match what you typed in to look for.  The addition I added was the “-i” parameter which says to “ignore case” which is the magic to let it match your string with uppercase characters against the output of “defaults” which is lower case. This will filter out everything except those that match your app.

 

Rob

Aha!

Thanks a lot Rob  :smiley:

I didn’t notice @funkyfishions used small characters.

The -i parameter is nice to know about.

Thanks a lot for explaining so thoroughly. 

This is a great feature, but having to put a hidden UI button in to clear out preferences is a bit of a pain.

It would be great if in a future version there was a separate .plist in the sandbox so it could be cleared out manually.

Just my $0.02

I don’t think too many people need a hidden UI button in production apps. For mobile devices, it shouldn’t be much different than it is now with a save settings file, you delete the app from your device and re-install a new one.

For desktop solutions on the Mac you have a command line command “defaults” that can be used to manage resetting things. On Windows, if you choose the Registry model you can use regedit.exe to deal with them. 

The simulator is a little more complex. It’s like desktops, but with the difference that all the settings are stored in the Corona Simulator’s preferences, not the apps, so you have to know your app’s unique signature and find that with either “defaults” or “regedit” to manage them. But in either case with the right information you could write the necessary command line scripts (batch files) to automate your needs.