views:

19

answers:

1

I am storing a username in CFPreferencesCopyAppValue. Under iOS 3.1.3 it works as expected but in iOS4 it stores it while the App is open but as soon as its closed (using the multitasking close ability) the variable isn't stored, ie on relaunch of the App its null.

I have a feeling it might be an issue with the multitasking as the App is closed a bit differently than in iOS 3 and therefore not saving on the App being closed.

I am unfortunately not using the most up to date version of the SDK so it might be fixed in later releases but I need the App to work under 3.1.3 and 4.0 and this is the last version of the SDK that has 3.1.3 and 4.0 without the need to have multiple installs. So if it is fixed on the final version I guess I have to have multiple installs.

Any light on the matter is appreciated.

+1  A: 

It may be useful if you post some actual code of how you are trying to update the value. As per the CFPreferencesCopyAppValue documentation:

Note that values returned from this function are immutable, even if you have recently set the value using a mutable object.

And the Preferences Best Practices document specifies that you should be using CFPreferencesSetAppValue to save the value.

Update: I suspect I am missing something in your scenario and maybe my answer below is what you're doing, since you did mention that your current code works on 3.1.3.

If that's the case, you might want to specify on which event are you saving the value. It might be that you're updating it when your app is being shut down, but if you have not explicitly specified in your plist you don't support suspend, your app might just be suspended.

Update2: The CFPreferencesSetAppValue documentation explicitly mentions:

You must call the CFPreferencesAppSynchronize function in order for your changes to be saved to permanent storage

Franci Penov
I am using CFPreferencesSetAppValue to set the value early on in the code and in both iOS 3 and 4 can retrieve them properly later on. The value is set to CFPreferences and retrieved from it before the app is closed. In iOS3 it works fine and in iOS4 it resets to null. Im not doing anything when the App closes or pauses or anything, but maybe the OS stores items like CFPreferences in flash storage on App close which doesn't happen in iOS4 and hence why its failing , don't know
Rudiger
Thanks, that seems to have worked. Strange though how I didn't call that but under iOS3 it worked and iOS4 it didn't. Think that was the thing confusing me
Rudiger