Unarchiving problem using NSKeyedUnarchiver
I am saving my application's state using NSKeyedArchiver.
NSMutableData *data;
NSKeyedArchiver *archiver;
data = [NSMutableData data];
archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:MyObjectToSave forKey:@"SavedStateKey"];
[archiver finishEncoding];
[data writeToFile:@"/tmp/SavedState" atomically:YES];
NSLog(@"Encoding Done");
[archiver release];
And Decoding the savedObject by the following code:
NSData *data;
NSKeyedUnarchiver *unarchiver;
data = [NSData dataWithContentsOfFile:@"/tmp/SavedState"];
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
MyObjectToSave = [[unarchiver decodeObjectForKey:@"SavedStateKey"] retain];
[unarchiver finishDecoding];
[unarchiver release]
The Coding is working fine on the simulator.
When running on the real device, It saves the state successfully but at the decoding time, it gives the following error:
* -[NSKeyedUnarchiver initForReadingWithData:]: data is NULL
i have tried changing the location to following with no luck.
[data writeToFile:@"SavedState" atomically:YES];
Is there any specific folder in the device, where i need to save the archeived data.
Thanks in advance.
Macbook, Mac OS X (10.5.5)