1

I am designing an app that will come bundled with some audio files. They'll total about 50MB in size. The app will allow you to download other audio files via in-app purchase. My goal is to have all of these files stored in one location (the Documents Directory).

What I'm doing in my code is this:

  1. On first launch, copy the bundled songs from Main Bundle Resources to the documents directory.
  2. Delete the files from their original location in the Main Bundle Resources.

I have all of this working fine so I know it's possible to do. My question is can anyone point me to Apple documentation/guidelines that says I'm not allowed to do this? Or, is this perfectly acceptable according to Apple's guidelines? I know they don't want you writing to the Resources folder, but haven't been able to find a definitive answer on deleting.

Sam
  • 7,252
  • 16
  • 46
  • 65
tptcat
  • 3,894
  • 2
  • 32
  • 51
  • You shouldn't copy things into the Documents directory that exist in the .app. This is a big no-no. It's a waste of space and your app will actually be rejected because you are storing them in the wrong place (they will be backed up to iCloud for example, wasting more space). Just write a routine for locating files which first checks the main bundle, then falls back on where downloaded files are stored (e.g. Caches directory). It's also not possible to delete files from the app bundle due to sandboxing restrictions. – Mike Weller Aug 30 '13 at 13:55

2 Answers2

3

It is not acceptable and will not work when running on a device (I guess you're testing on the simulator). You can't edit the bundle contents. The bundle is signed and editing it will invalidate the signature.

It would be advisable to deploy the app without the audio files and then to start downloading them as soon as there is a (suitable) internet connection after first launch (if this is an option for you).

Wain
  • 118,658
  • 15
  • 128
  • 151
  • It works fine on the device. That said, I guess I can't see if the files are being deleted, but I can tell they're being copied (which is obviously allowed). – tptcat Aug 30 '13 at 13:18
  • 4
    Given the specific issue, the solution is probably to just abstract finding the files so that most of the app doesn't have to care whether it is in the bundle or in the Documents directory. Note that the Documents directory is typically for user documents, and has special handling in iTunes. Typically app files should go in `~/Library/Application Support`. – Rob Napier Aug 30 '13 at 13:19
  • Thanks Rob. You're correct that that's probably the best solution. And, my files are actually partially stored in Documents (some files I want for iTunes sharing) and Application Support (for just playing on the device). I just simplified my question a bit. – tptcat Aug 30 '13 at 13:21
3

The documentation you're looking for is in the App Distribution Guide [emphasis mine]:"

Code signing your app allows the operating system to identify who signed your app and to verify that your app has not been modified since you signed it. Your app’s executable code is protected by its signature because the signature becomes invalid if any of the executable code in the app bundle changes. Note that resources such as images and nib files are not signed; therefore, a change to these files does not invalidate the signature.

That said, as I noted in my comments on @Wain's answer, this probably isn't a great thing to do if the files are read-only. It adds a big copy step on first launch, and you have to deal with it again on every upgrade.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • Thanks. That's what I was looking for. I agree it's not a great idea and will most likely follow your advice, but at least I know if I choose to it _shouldn't_ be rejected because of that. – tptcat Aug 30 '13 at 13:27