views:

361

answers:

3

I have created an app which uses Application Settings and user defaults following the example in the book "Beginning iPhone Development". In some cases my settings seem to disappear. If I launch the simulator I can go into settings and see it, I can then open my app and my settings can be read from within the app. If I then leave my app and go back into the settings screen I can no longer see the settings for my app!

I'm new to iPhone dev, is there something obvious that I'm overlooking?

Thanks.

+2  A: 

Seen that regularly, not worried so far. When developing app, I reinstall application into iPhone simulator several dozens of times a day. When opening Settings application I usually don't see my app at first. Just close and reopen Settings and now it's there.

It's the way simulator works (see below). If you want to test your app settings, close and reopen your app. Don't reinstall, since that overwrites your existing settings.

Quote from Apple's docs (bit.ly/1alQ2Y): "Each time you reinstall your application, iPhone OS performs a clean install, which deletes any previous preferences. In other words, building or running your application from Xcode always installs a new version, replacing any old contents. To test preference changes between successive executions, you must run your application directly from the simulator interface and not from Xcode." (thanx cagreen).

Btw a bit related: I made changed into app settings and did not see those values in simulator. When checking actual .plist files I always found there the real up-to-date values. Had to uninstall and reinstall my app, overwriting did not work. Sometimes even this didn't work, either Xcode or simulator was caching old values! Partial solution was to start updating application version number (CFBundleShortVersionString).

JOM
It's not a bug. As per my comment below, this is working as designed. ALTHOUGH, it can be a real pita when trying to test settings/preferences.
cagreen
Thanx cagreen, great info! Your comment copied here: It's working as expected. From Apple's docs (bit.ly/1alQ2Y): "Each time you reinstall your application, iPhone OS performs a clean install, which deletes any previous preferences. In other words, building or running your application from Xcode always installs a new version, replacing any old contents. To test preference changes between successive executions, you must run your application directly from the simulator interface and not from Xcode."
JOM
+1  A: 

When you run an app in the simulator, the app is located in

~/Library/Application Support/iPhone Simulator/User/Applications/appid

where appid is a uniquely generated UUID for each app. The user settings for that app are in

~/Library/Application Support/iPhone Simulator/User/Applications/appid/Library/Preferences

I've noticed that if you leave the simulator running, it will use the same appid every time you run the app but if you quit the simulator it will give it a new appid the next time you run the app and it will lose its settings.

Ferruccio
A: 

has anyone experienced this?? it happens to me every other time I run the app in the simulator...

is there something that can be done to avoid this issue??

CocoaNewBee
It's working as expected. From Apple's docs (http://bit.ly/1alQ2Y):"Each time you reinstall your application, iPhone OS performs a clean install, which deletes any previous preferences. In other words, building or running your application from Xcode always installs a new version, replacing any old contents. To test preference changes between successive executions, you must run your application directly from the simulator interface and not from Xcode."
cagreen