1

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

phil
  • 21
  • 3
  • One more item. Is there something I need to set in a plist file? an entitlements file? a distribution profile? any other file I should include? – phil Oct 14 '14 at 21:58

1 Answers1

0

I have encountered a similar issue on an app upgrade i made recently. I save .epub and .pdf files in the Documents folder. Users reported that after the upgrade those are not found by the app. In my opinion the files are either deleted during upgrade or for whatever reason the app cannot access them.

I cannot reproduce the issue. I usually use Testflight for distribution or installation from Xcode. Users reported the issue on both ios7 and ios8 devices.

I haven't found the cause but here are the leads i have followed :

  1. Access to Documents folder is done by absolute path Not the case for me and if so, it should also happen on Testflight upgrade. See related : First App Update, User Data Lost (was stored in Documents directory)

  2. Change of dev Teams for app. That is the case for me as i had previously moved the app from one developer account to another. But from what i know iOS should move the contents of the old Documents folder to the new one anyway See related Managing Data Across Updates section: https://developer.apple.com/library/ios/technotes/tn2285/_index.html

  3. Incorrect usage of NSURLIsExcludedFromBackupKey for the files. I set it to yes. This post iOS App update new version delete files from Documents folder seems to suggest that files marked in such a way might not be copied at upgrade see "If you mark a file so it is excluded from backup then that means the file can easily be replaced.When you install the app update, those files aren't copied over to the updated app" Haven't found any confirmation on this one in any Apple docs

  4. Also related to NSURLIsExcludedFromBackupKey setting. If iCloud is activated and this setting is set to No, then this files might get deleted through iCould. See ios8 iCloud issues http://www.macrumors.com/2014/09/29/reset-all-settings-icloud-drive-bug/ Also this is not the case for me as users reported issues on ios7 a well.

Does any of the above sound familiar for your implementation?

Community
  • 1
  • 1
Daniela
  • 1
  • 1