When I update from iOS 4+ to iOS 5, I lose all data in my own app. I also upgraded to OSX Lion and Xcode 4. I back up my iPhone in iTunes and was able to get the data using iPhone Backup Extractor.
I save my app data to a file in the following way:
- (NSString *)iouArrayPath
{
// Standard way of getting file path for iOS
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *dir = [paths objectAtIndex:0];
NSLog(@"Directory: %@", dir);
return pathInDocumentDirectory(@"IouTableArray.data");
}
- (void)archieveIou
{
NSLog(@"archieveIou");
// Get the path to the document directory
NSString *iouPath = [self iouArrayPath];
// grab the objects to archieve
NSMutableArray *iouTableArray = [iouViewController iouTableArray];
// ARCHIVE DATA
NSMutableData *data = [NSMutableData data];
NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
[archiver encodeObject:iouTableArray forKey:@"IouTableArray"];
[archiver finishEncoding];
[data writeToFile:iouPath atomically:YES];
if([data writeToFile:iouPath atomically:YES]) {
NSLog(@"writeToFile success!");
}
else {
NSLog(@"writeToFile failed");
}
[archiver release];
}
This is what I’ve tried to understand. I open the project in Xcode 4, I copy the .data file from the backup and paste it to the /iPhone Simulator/5.0/Applications/Some digit/Documents. Theorectically, when the app starts, it will look into that folder and load the .data file if it exists. It does not. However, the app will work fine if I create some test data and save it. It will replace the backup file with the same file name and properly load it when I restart the app.
This makes me wonder if there is some NSCoder/archieving change between XCode3/XCode4 or between iOS4 and iOS5.
Does anyone know what is going on? Once I figure this out, I plan to use the backup data file and copy it to the current app /Document folder. Actually, come to think of it, I am not sure how to do that either. The /Document folder for the app reside within the phone. I’ll have to see if I can use iTunes and inject the app with the data. Anyways, first things first! Understand the system.
Thanks!
It turns out that iOS5 installs an older version of the app. Strange but make sure you get all your provisioning squared out.