5

I am new to iOS development. My app got rejected from the review, stating the following reason,

2.23 Apps must follow the iOS Data Storage Guidelines or they will be rejected

We found that your app does not follow the iOS Data Storage Guidelines, which is required per the App Store Review Guidelines.

I am not storing my DB file in documents directory. Here's my code,

NSString *libraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) lastObject];
NSString *path = [libraryPath stringByAppendingPathComponent:@"DatabaseFolder"];
NSURL *pathURL = [NSURL fileURLWithPath:path];
BOOL isDirectory = NO;
if ([[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDirectory]) {
    if (isDirectory) {
        return pathURL;
    } else {
        // Handle error. ".data" is a file which should not be there...
        [NSException raise:@"'Private Documents' exists, and is a file" format:@"Path: %@", path];
    }
}
NSError *error = nil;
if (![[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:&error]) {

    [NSException raise:@"Failed creating directory" format:@"[%@], %@", path, error];
}
return pathURL;

How to reproduce a crash or bug that only App Review or users are seeing?

Community
  • 1
  • 1
Madhavan89
  • 53
  • 4
  • show remaining line of app store rejection reason? – Mani Feb 20 '14 at 07:22
  • Yes, this is what you are probably looking for: http://stackoverflow.com/a/9410523/2500457 – iphondroid Feb 20 '14 at 07:23
  • Man I was too late setting up my github. You should check out my answer also. Cause you can also set the do not archive bit. The problem with the checked answer is that the OS can delete that data if it needs space. I wouldn't store anything you need later in caches. If you're keeping high scores for example or other app progress. I'd use the data directory as shown in my code. – badweasel Feb 20 '14 at 07:46

3 Answers3

2

The iOS Data Storage guideline document (login required to view) says,

Everything in your app’s home directory is backed up, with the exception of the application bundle itself, the caches directory, and temp directory.

This means even your NSLibraryDirectory directory contents gets backed up to iCloud. To resolve this you have following options,

  • Use the /tmp directory for storage
  • Use the /Caches directory for storage
  • Only use the /Documents directory for user-generated content that cannot be re-created.
  • Set the do not backup attribute on the file using setResourceValue:forKey:error: method of NSURL.

Here is how you can mark a resource for not backing up to iCloud.

- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
    assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);

    NSError *error = nil;
    BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES]
                              forKey: NSURLIsExcludedFromBackupKey error: &error];
    if(!success){
        NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
    }
    return success;
}

Hope that helps!

Amar
  • 13,202
  • 7
  • 53
  • 71
0

I assume the reviewer doesn't like that you are storing the database in the library folder and there within one created by you. If you read the mentioned guidelines you'll see that you shouldn't store there.

Data that can be downloaded again or regenerated should be stored in the /Library/Caches directory. Examples of files you should put in the Caches directory include database cache files and downloadable content, such as that used by magazine, newspaper, and map applications

Volker
  • 4,640
  • 1
  • 23
  • 31
  • 1
    If the data he's storing there is something the user will expect to get to later, something semi-important, he should not store it in caches. The caches directory can be deleted at any time by the OS if it needs the space. – badweasel Feb 20 '14 at 09:20
0

I had this problem for a while also. So I made a class to handle this for me. There are different rules of where you can store stuff in different OS's. So my class checked the OS and returned a proper data director for each one and even handled the migration of data from one location to the other if the OS was updated.

But pretty much today you could just support the 5.1 and up location and be fine.

The key is that you need to set your do not backup attribute also.

I just put in a github here: https://github.com/badweasel/BWFileManager

badweasel
  • 2,349
  • 1
  • 19
  • 31