NSURLIsExcludedFromBackupKey - Applications must follow iOS storage guidelines or they will be rejected

My application was rejected because it seems that 7 mb are stored in a folder with documents, and they are automatically sent to icloud. Therefore, I looped through all the files that will be written to the document folder through this method:

- (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;
  }

1.1 . 1.2 ( , , , addSkipBackupAttributeToItemAtURL). . temp cache, ( - db, db ), , , , :

[self addSkipBackupAttributeToItemAtURL: [NSURL fileURLWithPath: fullPath]];

[NSURL fileURLWithPath: fullPath] ios 5.1, , . nsurl [NSURL URLWithString: defaultStorePath], 5.1, , .

ios 5.0.1 , [NSURL URLWithString: defaultStorePath] , [NSURL fileURLWithPath: fullPath].

, ios nsurl, - . :

, , / 7mb. , :

  • > iCloud > >
  • " "

, 7 mb nsurl ( ). ? - ? - , apple, ?

+5
2

, , NSURLIsExcludedFromBackupKey , . , Library/Application Support ( /tmp /Caches):

// store in /Library/Application Support/BUNDLE_IDENTIFIER/Reference
// make sure Application Support folder exists
NSURL *applicationSupportDirectory = [[NSFileManager defaultManager] URLForDirectory:NSApplicationSupportDirectory
                                                                            inDomain:NSUserDomainMask
                                                                   appropriateForURL:nil
                                                                              create:YES
                                                                               error:&error];
if (error) {
    NSLog(@"KCDM: Could not create application support directory. %@", error);
    return nil;
}

NSURL *referenceFolder = [applicationSupportDirectory URLByAppendingPathComponent:@"Reference" isDirectory:YES];
if (![[NSFileManager defaultManager] createDirectoryAtPath:[referenceFolder path]
                               withIntermediateDirectories:YES
                                                attributes:nil
                                                     error:&error]) {
    NSLog(@"KCDM: Error creating Reference folder to store model %@: %@", modelName, error);
    return nil;
}

BOOL success = [referenceFolder setResourceValue:@YES forKey: NSURLIsExcludedFromBackupKey error: &error];
if(!success){
    NSLog(@"KCDM: Error excluding %@ from backup %@", referenceFolder, error);
}
+2

, , . iCloud, "- > →

, . , skip :

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

   if (&NSURLIsExcludedFromBackupKey == nil) { // iOS <= 5.0.1
      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;
   } 
   else { // iOS >= 5.1
      NSError *error = nil;
      [URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];
      return error == nil;
   }


}
0

All Articles