CFPreferencesCopyAppValue not working under iOS 4
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.开发者_JS百科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.
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
精彩评论