1

My application just got rejected from Apple because I store my resources under Documents folder! The Documents folder gets synched to iCloude automatically so only user generated data should be stored under Documents. All application data should go under Application bundle.

I use following method through out my project

- (NSString *)filePath:(NSString *)fileName {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *path = [documentsDirectory stringByAppendingPathComponent:fileName];
    return path;
}   

For example, following line unzip my resources under documents folder.

[SSZipArchive unzipFileAtPath: zipFileName toDestination:[self filePath: @""]];

How can I move these files and Resources folder images into Application bundle and access them?

[EDIT]

- (NSString *)filePath:(NSString *)fileName {
    NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/DoNotBackUp"];
    if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
        [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:NO attributes:nil error:nil];
        // Set do not backup attribute to whole folder
        if (iOS5) {
            BOOL success = [self addSkipBackupAttributeToItemAtURL:path];
            if (success) 
                NSLog(@"Marked %@", path);
            else
                NSLog(@"Can't marked %@", path);
        }
    }
    path = [path stringByAppendingPathComponent:fileName];

    return path;
}

/*
 set the document files attribute to marked "do not backup"
*/
- (BOOL)addSkipBackupAttributeToItemAtURL:(NSString *)path
{
    const char* filePath = [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;
}

Where iOS5 is BOOL variable:

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

iOS5 = NO;
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"5.0.1")) 
    iOS5 = YES;

Thanks.

Paresh Masani
  • 7,474
  • 12
  • 73
  • 139

2 Answers2

2

in iOS 5.0.1 yo can add a new file attributo to mark them as non iCloud sync:

#include <sys/xattr.h>
- (void) AddSkipBackupAttributeToFile: (NSURL*) url
{
    u_int8_t b = 1;
    setxattr([[url path] fileSystemRepresentation], "com.apple.MobileBackup", &b, 1, 0, 0);
}
javieralog
  • 1,337
  • 9
  • 10
1

You cannot write to the Bundle at runtime. You can only add resources to the bundle when creating the binary. You will need to place the results of the unzip process into the Caches Directory.

Because the contents of this folder can be deleted at any time by the system, you should check at every startup if the file needs to be unzipped again.

You will likely only need to change the first line of the above method to:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
Felix Lamouroux
  • 7,414
  • 29
  • 46
  • OMG then how would I support my automatic CMS stuffs from website? If I update my app from website, my iPhone App automatically downloads it and updates document folder. I can't afford downloading whole Application zip if its not available locally as its huge file! Once local files updated I want to make sure it is permanent because it updates the version and synchronize with server so that server knows what version of files iPhone has and send changes if required. If files deleted then my App might go in inconsistent state! – Paresh Masani Nov 21 '11 at 09:46
  • In that case you will need to flag it as permanent. iOS 5.0.1 added file system attributes for that. – Felix Lamouroux Nov 21 '11 at 09:56
  • Hi Felix, based on https://developer.apple.com/library/ios/#qa/qa1719/_index.html document, I shouldn't marked "do not backup" for files under Documents folder. so I have to go for what you suggested here. Apple also mentioned that Cache files might be removed in low storage situation. I couldn't find how to make my files permanent. Could you please give me some example? – Paresh Masani Nov 23 '11 at 10:32
  • 1
    Offline Data This is data that can be downloaded or otherwise recreated, but that the user expects to be reliably available when offline. Offline data should be put in the /Documents directory or in the /Library/Private Documents directory (see QA1699 for details) and marked with the "do not backup" attribute. Data stored in either location will persist in low-storage situations and the "do not backup" attribute will prevent iTunes or iCloud backing up the data. Offline data files should be removed as soon as they are no longer ... – Felix Lamouroux Nov 23 '11 at 12:08
  • So it appears that you need to keep the files in Document, but at the attributes for "No backup" – Felix Lamouroux Nov 23 '11 at 12:08
  • Cool gotcha! Updated code and submitted App. Hopefully this time it will went through! – Paresh Masani Nov 23 '11 at 15:29
  • Hi Felix, I have added code. Please let me know if I am missing anything. Thanks. – Paresh Masani Nov 23 '11 at 15:38
  • @AppleDeveloper did your app went through ? how do u manage iOS 5 Storage ? – Desmond Feb 01 '12 at 01:37
  • Yah our App approved after I marked DoNotBackup folder to not to backup automatically on iCloud. What you mean by iOS 5 storage? As you see in my edited question, I check if system version is iOS 5 or more I marked my folder else not! – Paresh Masani Feb 02 '12 at 10:37