5

My app was rejected cause it must follow the iOS Data Storage Guidelines. I have already read some answer here on stackoverflow, and i have already read some blogs... I know my problem, at first application launch i copy 1 sqlite db and unzip some images in documents folder. The problem it's icloud that automaticcaly backup any files in documents directory. I don't need to use icloud in my app but my files must remain in document folder because they are the base data of my application and must be persit (cache folder or temp folder aren't correct solutions). So i've read about a flag that i can set file by file to forbid the backup :

[URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:nil];

I have also read that this method works only in ios higher than 5.0.1, in the other it will be simply ignored (i have setted my ios deployment target to 4.3)... If i use this method my app will be rejected again because the older ios devices backup aren't managed? If yes there is a cross-iosversion method to set the NSURLIsExcludedFromBackupKey?

EDIT I'm sorry icloud isn't present in ios earlier 5.0 so i think that the problem regards only differences beetween version 5.0 and 5.0.1, I'm wrong?

Kara
  • 6,115
  • 16
  • 50
  • 57
Cri1682
  • 513
  • 8
  • 21
  • Check this link http://stackoverflow.com/questions/8818117/application-rejected-because-of-not-following-ios-data-storage-guidelines Thanks!! – Kiran Apr 18 '12 at 09:26
  • thank you but i have already read this answer, i have still some dubts...Some of the links seems to tell "the only solution to have the app approved is to copy file in cache folder.If you only set "do not back up" attribute" and leave files in documents folder the app will be rejected anyway. I can't copy files to cache folder,this folder can be purge in low memory situation and my files are foundamentals for my application, there is a db that will be updated with in-app contents,i can't tell to users that sometimes they have to re-download the in-app package. – Cri1682 Apr 18 '12 at 09:46
  • Why do you want to unzip files in documents directory from bundle ? you can keep those in bundle itself ? any specific reason for that ? – Janak Nirmal Apr 18 '12 at 10:04
  • i have to update the db with the package downloaded of some non ordered in-app purchase and the user can insert personal data in the db. If i use the bundle db and then i want to update the app to an higher version of the by itunes the user will lost all the custom data – Cri1682 Apr 18 '12 at 10:17

4 Answers4

3

I have passed all files that will stored in documents folder through this method.

Try this

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

I've found this method here in Stack Overflow:

Community
  • 1
  • 1
Cri1682
  • 513
  • 8
  • 21
  • Please can you provide me the sample of NSURL. I passed the TEST sub folder of Document directory. but my application is rejected. So please suggest. thx – Mitesh Khatri May 14 '12 at 09:06
  • 1
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDir = [documentPaths objectAtIndex:0]; NSString *imgPath = [documentsDir stringByAppendingPathComponent:@"img.jpg"]; [self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:imgPath]]; I don't know if i really understand the question but this is an example of the nsurl that i have passed trought the method of the answer...is a simple nsurl that point to a file in the documents directory. – Cri1682 May 14 '12 at 10:42
  • 1
    Ok. But i want to apply it on whole folder than? it will work? – Mitesh Khatri May 14 '12 at 11:01
  • Does this mean I still can save downloaded data to Documents folder without being rejected if I set the "don't backup" flag to my files? – Bagusflyer Mar 31 '13 at 16:02
3

NOTE: do not use

NSString *mediaDir = [NSString stringWithFormat:@"%@/Library/Caches/%@", NSHomeDirectory(), MEDIA_DIRECTORY];

since you are making assumptions about the name. rather, use:

NSArray* lCachePaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString* lCacheDirectory = [lCachePaths objectAtIndex:0];
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Hector
  • 151
  • 1
  • 4
1

In my app I solved it by adding the files (images in my case) to the bundle, and check in the method where I load the images if they exist in the document folder where the user generated data / images will be placed.

If it isn't there, I know it's one of my prepopulated images and I load it from the bundle.

For the sqlite file: Not a really satisfying solution, but I create the data in code now, instead of a prepopulated sqlite file.

Thyraz
  • 2,412
  • 2
  • 21
  • 23
  • thanks,i have also some images to copy in document folder and maybe your solution is good but my first problem was the db,i can't create the data in code – Cri1682 Apr 18 '12 at 10:25
  • Why are you copying the images rather than using them directly out of the bundle? – hypercrypt Apr 23 '12 at 11:03
1

For media files, we store them in the Caches/ directory. During application startup, we check if they are there. Otherwise the images are either loaded from the bundle (in your case unzipped) or in our case re-downloaded from the Server.

The exact location is

NSString *mediaDir = [NSString stringWithFormat:@"%@/Library/Caches/%@", NSHomeDirectory(), MEDIA_DIRECTORY];

which is the place where you SHOULD store your temporary files. The files in the cache are generally persistent, much more so than in Temp, but can be deleted at some point.

Blitz
  • 5,521
  • 3
  • 35
  • 53