I let the user make changes to their settings in the settings area of the iphone. During the next network sync i\'d like to send the user changes to the server. But only if the
Ah silly me! Here we go with an elegant way. Search for AppPrefs in the Apple Documentation within XCode and it'll show an example app which does exactly what you want to do. Just compile and run! It makes use of the NSUserDefaultsDidChangeNotification.
This is the code being used to register an observer:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(defaultsChanged:)
name:NSUserDefaultsDidChangeNotification
object:nil];
Old answer:
It doesn't look like as if you could get a modification date out of the NSUserDefaults. So far I only can think of this way:
NSUserDefaults *previousDefaults = [someInstance previousUserDefaults];
NSUserDefaults *currentDefaults = [NSUserDefaults standardUserDefaults];
if([previousDefaults isEqualToDictionary:currentDefaults])
{
[someOtherInstance sendModifiedUserDefaultsToServerWithDefaults:currentDefaults];
[yetAnotherInstance saveModified]
}
You have to save the user defaults yourself as dictionary to disk when the app is launched the first time: your default values. Then, everytime the app is opened you compare those two dictionaries. If they