PDA

View Full Version : archive / Unarchive




sujithkrishnan
Jul 14, 2008, 06:48 AM
In my iPhoneApp ,

I am archiving an object for the first run, using the archived object from next run..
But my application returning NO for variable success for the code below in device, however in simulator, its returning YES and unarchiving the file to retrieve values...


NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"customerInfo.xml"];
BOOL success = [fileManager fileExistsAtPath:writableDBPath];


if(success == YES)
{
CustomerInfo *cobj;
cobj = [NSKeyedUnarchiver unarchiveObjectWithFile:writableDBPath];
[CustomerInfo setCustomerObject:cobj];
}



Archiving (which is returning YES both in device and simulator....)


NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writableDBPath = [documentsDirectory stringByAppendingPathComponent:@"CustomerInfo.xml"];
BOOL success = [NSKeyedArchiver archiveRootObject:[CustomerInfo getCustomerObject] toFile:writableDBPath];


One thing which is strange that its returning YES for the archiving part both in device and simulator.

IN DEVICE....
If i am archiving and checking for the file suddenly, its showing "FILE IS THERE"...means archiving the file returns YES... My question is eventhough the file is not archived properly, whether the archive function return "YES" ??


I am saving the file in doc.directory...
I am doing same kind of archiving for another BIG object, but its working fine with simulator and device...