StackOverflow:
I need help. I have an app in the app store that collects user input (text) and saves it to an archive file (NSKeyedArchiver) in the Documents folder of the app sandbox. The data is refurbished on launch via NSKeyedUnarchiver. This process has been running fine for several updates. I’ve just released an update of the app to the iTunes Store and I have people claiming their data is gone. My problem is I’m unable to reproduce the failure.
I now have both an iPhone and an iPad version of the app and in the iPhone version I rename an old filename to the same name that the iPad uses; this is done in didFinishLaunchingWithOptions:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
. . .
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
// get full path to Document subdirectory
NSString *documentFolder = [paths objectAtIndex:0];
// form full path for both old and new archive filenames
self.archiveFile = [documentFolder stringByAppendingPathComponent:oldArchiveName];
NSString *newArchive = [documentFolder stringByAppendingPathComponent:newArchiveName];
NSLog(#” *** self.archiveFile (%@)”,self.archiveFile);
NSLog(#” *** newArchive (%@)”,newArchive);
// let’s rename the archive
NSFileManager *fm = [NSFileManager defaultManager];
// if the old archive filename exists change it to the new name
if([fm fileExistsAtPath:self.archiveFile])
(void)[fm moveItemAtPath:self.archiveFile toPath:newArchive error:nil];
// self.archiveFile now points to the new archive file
self.archiveFile = newArchive;
NSLog(#” *** self.archiveFile (%@)”,self.archiveFile);
. . .
}
From the Console subwindow of Xcode’s Devices window:
Oct 14 14:02:46 Randy-Merritts-iPad phoneFilebox[11096] : *** self.archiveFile (/var/mobile/Containers/Data/Application/3BF0757B-96F4-4AAA-9CEB-6C87505CA6BD/Documents/cabself.xobeliF)
Oct 14 14:02:46 Randy-Merritts-iPad phoneFilebox[11096] : *** newArchive (/var/mobile/Containers/Data/Application/3BF0757B-96F4-4AAA-9CEB-6C87505CA6BD/Documents/iFilebox.cabinet)
Oct 14 14:02:46 Randy-Merritts-iPad phoneFilebox[11096] : *** self.archiveFile (/var/mobile/Containers/Data/Application/3BF0757B-96F4-4AAA-9CEB-6C87505CA6BD/Documents/iFilebox.cabinet)
The complaints from my users suggests the app’s attempt to open ‘self.archiveFile’ is failing (if an archive is not found in Documents this is taken to mean you’re a new user and I create an empty archive ready to receive new data). And there’s the problem: it NEVER fails for me. Furthermore, once the new update is installed, you can enter new data, terminate the app, relaunch the app, and all the (new) data is there. If there’s a programmming flaw in how I unarchive the data, wouldn’t this failure be repeatable?
I’ve used both Xcode 6.0.1 Devices window to install new builds as well as www.diawi.com to distribute test versions to team members and none of us have ever lost any data; note these two methods strictly perform an update; they do not (nor have any reason to) disturb the Documents subdirectory.
However, we can reproduce the data loss problem by downloading a copy from the App Store. It appears the App Store download / in-device app update process is resetting the Document folder and deleting any previous files.
Has anyone seen this? Is anyone aware of this problem? Why would an install of an upgrade from the App Store