Application rejected due to data storage - how can I make it ignore all my files in a folder?

I have an application that downloads a ton of photos and stores them in subfolders of the Documents folder, which, apparently, was beautiful, so far iOS 5.1

Now Apple tells me that I need to save them elsewhere or somehow mark them as not for backup. This is an application update, so for most of my users, data already exists in these subfolders.

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

It would be a HUGE commitment to move all files to the cache, as they assume.

I read this, but I don’t know exactly where I should implement this: https://developer.apple.com/library/ios/#qa/qa1719/_index.html

+6
source share
1 answer

You can use NSFileNanager to list all files, and then call the function of your choice. Your code will be something like this:

// 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 it like this:

  NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; [self addSkipBackupAttributeToItemsInFolder:documentsDirectory]; 
+5
source

Source: https://habr.com/ru/post/917041/


All Articles