Backup prevents using the app in iCloud

The Apple retention rule method method poses more problems for me, because most of the data that I support from the Documents directory (files, dataBase and some material related to the application). I recently uploaded a binary file to the application store and it provided me with a report Apple rejection report according to this point. I am going to change my code as below

- (NSString *)applicationDocumentsDirectory { NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]; NSURL *pathURL= [NSURL fileURLWithPath:documentPath]; [self addSkipBackupAttributeToItemAtURL:pathURL]; return documentPath; } - (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL { 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; } 

MY QUESTIONS:

1. I can use the addSkipBackupAttributeToItemAtURL: method directly in the document directory to strip the iCloud backup for all my files in the document directory.

2. This code is sufficient to approve my application in the application store if my last binary code is rejected due to the attribute β€œdo not back up”, which is not included in the directory of my documents.

+4
source share
2 answers

You must set this attribute to a folder to avoid backing up the full folder.

Please note, however, that this may be a good approach to do this in the full Documents folder. First of all, this will create a situation where you do not have backup storage, so when restoring the phone, the application will be in a state of vanilla. I can also assume that this is simply not the way Apple intended, and therefore could lead to a rejection of the application (always guesswork). If possible, I will create a subfolder for your content that is not supported by the backup in the Document directory and place everything there (this may require some kind of migration code, although if you already have a version of this application in the store).

Please note that the storage recommendations allow you to store user-created / non-recoverable content in the Documents directory, and you only need to mark things like downloaded content, etc. that cannot be placed in the Caches directory (for example, if the user expects that this content will be available offline).

+1
source

Use this function

 -(BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL { const char* filePath = [[URL path] fileSystemRepresentation]; const char* attrName = "com.apple.MobileBackup"; if (&NSURLIsExcludedFromBackupKey == nil) { // iOS 5.0.1 and lower u_int8_t attrValue = 1; int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0); return result == 0; } else { // First try and remove the extended attribute if it is present int result = getxattr(filePath, attrName, NULL, sizeof(u_int8_t), 0, 0); if (result != -1) { // The attribute exists, we need to remove it int removeResult = removexattr(filePath, attrName, 0); if (removeResult == 0) { NSLog(@"Removed extended attribute on file %@", URL); } } // Set the new key NSError *error = nil; [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error]; return error == nil; } } 

this is the .thanks code implemented

0
source

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


All Articles