Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App does not store any content in document directory but Appstore reject

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?

like image 419
Madhavan89 Avatar asked Nov 01 '22 04:11

Madhavan89


1 Answers

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!

like image 154
Amar Avatar answered Nov 11 '22 15:11

Amar