0

My app got rejected because Apple found that on launch and/or content download, my app stores 14.18 MB.

Now I'm trying to skip backup of all the images and sounds I use in the game.

So far, I made a folder called "Resources" in my app folder itself, looking like this: App Folder Scrshot

What I did in AppDelegate.m is next:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [self addSkipBackupAttributeToItemAtURL:[self applicationDocumentsDirectory]];
    return YES;
}

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

    NSError *error = nil;
    BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES]
                              forKey: NSURLIsExcludedFromBackupKey error: &error];
    if(!success){
        NSLog(@"Error excluding %@ from backup %@", [URL lastPathComponent], error);
    }
    return success;
}

This isn't working.

I have 2 questions:

1)Am I doing the right thing from the start? Should I put all the images and sounds in folder called Resources, and then skipBackup for the entire folder or should I put them somewhere else? If yes, then where? (I saw over internet people talking about "Documents" folder...but I don't know what that folder is nor where to find it.

2)If I could put everything in "Resources" folder, how to I reach that folder from the code? How do I make URL to that folder, from Xcode itself?

Thanks in advance

iamVishal16
  • 1,780
  • 18
  • 40
SteBra
  • 4,188
  • 6
  • 37
  • 68
  • I think you saw on internet about this document folder - http://stackoverflow.com/questions/2709705/read-text-file-in-document-folder-iphone-sdk – Shruti May 01 '14 at 10:59
  • From your image, the "Resources" is a group not a physical folder. Show us the entire Apple's rejection reason, perhaps we can help. – user523234 May 01 '14 at 11:01
  • This is their rejection reason: https://www.dropbox.com/s/r48ymxvzhgsn5oc/Screenshot%202014-05-01%2014.02.50.png – SteBra May 01 '14 at 12:03

2 Answers2

0

You should deliver the content with your app. downloading the content on first launch is not a good idea due to the connection issue if user is on 3G/Edge.

the document directory is on the device, a folder under your app, and its created by ios automatically. Apple Documentation

getting files from resource folder is easy files from resources

Community
  • 1
  • 1
Hashmat Khalil
  • 1,826
  • 1
  • 25
  • 49
0

I had this problem before ! The problem is not the size of what you store, it is where you store it. My guess is that you store your file in NSDocumentDirectory, which is bad because this directory should only be used to store data that the user created himself (documents, photo, etc). Adding the NSURLIsExcludedFromBackupKey is not enough. When it happened to me, I changed NSDocumentDirectory to NSApplicationSupportDirectory and my app got approved.

UPDATE

It is best if you first create a subdirectory in your NSApplicationSupportDirectory to store your file there.

Your methods should look like something like :

- (NSURL *) applicationDocumentsDirectory{
    NSString *appSupportDir = [NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES) lastObject];
    appSupportDir = [appSupportDir stringByAppendingPathComponent:@"MyAppDirectory"];
    return [NSURL URLWithString:appSupportDir];
}

And don't forget to create the directory first :

    if (![[NSFileManager defaultManager] fileExistsAtPath:[self applicationDocumentsDirectory] isDirectory:NULL]) {
        NSError *error = nil;        
        [[NSFileManager defaultManager] createDirectoryAtPath:[self applicationDocumentsDirectory] withIntermediateDirectories:YES attributes:nil error:&error];
    }
Emilie
  • 2,413
  • 13
  • 12
  • Hi Emilie. I think we are on the track here. Thing is, I never put anything anywhere..or I never specifically told program where to put what. So I guess it's using some defaults. This is the second app im publishing to an app store. I had no problem with the first one, and they are pretty much similarly made. So I never specified where to put which data, but somehow my first app is storing only 0.5mb on iCloud and this one stores 12Mb. Can you tell me where should I specify which files are stored where? is it in AppDelegate.m or somewhere else? Any tutorial would do as well :) – SteBra May 01 '14 at 12:21
  • @Stebra Can you post the code of your method `[self applicationDocumentsDirectory]` ? – Emilie May 01 '14 at 12:23
  • Here it is: - (NSURL *)applicationDocumentsDirectory { return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; } – SteBra May 01 '14 at 12:26
  • when I replace NSDocumentDirectory with NSApplicationSupportDirectory in [self applicationDocumentsDirectory], I get this error: Error excluding Application Support from backup Error Domain=NSCocoaErrorDomain Code=4 ... "The operation couldn't be completed. No such file or directory"} That's when I comment out assertion line. – SteBra May 01 '14 at 12:29
  • If I don't comment out assertion line, I get the following error:"Assertion failed: ([[NSFileManager defaultManager] fileExistsAtPath: [URL path]]), function -[AppDelegate addSkipBackupAttributeToItemAtURL:], file /Users/stefanbrankovic/Desktop/FessorsLounge 2/FessorsLounge/AppDelegate.m, line 54." – SteBra May 01 '14 at 12:32
  • @Stebra pretty sure it's because xCode don't want to remove complete support directory from backup. In my code, I store my files in a subfolder in `NSApplicationSupportDirectory`. See my update in my comment for more details – Emilie May 01 '14 at 12:41
  • Emilie, This thread is slowly becoming too long. So instead of answering here, I started a new question here: http://stackoverflow.com/questions/23408210/error-excluding-applicationsupportdirectory-from-backup Please, check it out :) – SteBra May 01 '14 at 13:00