Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App rejected because of Data Storage - how do I get it to ignore all of my files in a folder?

Tags:

ios

iphone

icloud

I have an app that downloads a ton of photos and stores them in a subfolder of the Documents folder which was apparently fine until iOS 5.1

Now Apple is telling me I need to store them else where or somehow mark them as not for backup. This is an app update so for most of my users the data will already exist in these subfolders.

How do I get iOS to skip all of the files in my subfolders of Documents or to skip a particular file in the Documents folder?

It would be a HUGE undertaking to move all of the files to the cache like they suggest.

I read this but I am no sure exactly where I am suppose to implement this: https://developer.apple.com/library/ios/#qa/qa1719/_index.html

like image 421
Slee Avatar asked May 30 '12 18:05

Slee


1 Answers

You can use NSFileNanager to list all the files, then call the function that is suggested in your like. Your code would be something like:

// From Apple FAQ
#import <sys/xattr.h>
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL
{
    assert([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]);

    const char* filePath = [[URL path] fileSystemRepresentation];

    const char* attrName = "com.apple.MobileBackup";
    u_int8_t attrValue = 1;

    int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
    return result == 0;
}


- (void) addSkipBackupAttributeToItemsInFolder:(NSString*)folder
{
    NSFileManager *fm = [NSFileManager defaultManager];
    NSArray *dirContents = [fm contentsOfDirectoryAtPath:folder error:nil];

    for (int curFileIdx = 0; curFileIdx < [dirContents count]; ++curFileIdx)
    {
        NSString* curString = [folder stringByAppendingPathComponent:[dirContents objectAtIndex:curFileIdx]];
        NSURL* curFileUrl = [NSURL fileURLWithPath:curString];
        [self addSkipBackupAttributeToItemAtURL: curFileUrl];
    }
}

And you will use this like that:

    NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
    [self addSkipBackupAttributeToItemsInFolder:documentsDirectory];
like image 115
J_D Avatar answered Nov 06 '22 23:11

J_D