سؤال

I am developing an iOS app which involves about 100Mb of data files which have to be copied into the application bundle. I do this as a build step; however this happens every time I build and every time I run the app. So if I build the app to test the code compiles, and then test it, the files get copied twice!

Is there a best practice for apps with large data files to avoid this problem, or if not how can I improve it?

I basically just have a "copy media folder" build phase which runs a few rsync commands through bash. The fact this is run even when I am just running an already-built app is really annoying, especially when testing on a real device.

My actual "Copy Media Folder" build phase does this:

CONTENTS_PATH="${TARGET_BUILD_DIR}/${CONTENTS_FOLDER_PATH}"
echo CONTENTS_PATH: $CONTENTS_PATH 

rsync -rvC ../rundir/assets $CONTENTS_PATH/Ogre3D
rsync -rvC ../rundir/config/ $CONTENTS_PATH/Config
هل كانت مفيدة؟

المحلول

Xcode's built in "Copy Files Build Phase" is the normal way to copy files to a product. Is there any reason you're not using it?

You can add additional copy phases from the "Editor" -> "Add Build Phase" menu, if needed.

If the files are all contained in a folder but shouldn't be added manually to the Xcode project, you can use a folder reference (the blue folders in the project navigator).

The advantage of this build phase is that it uses Xcode's dependency tracking, so it does not copy files that have not changed.

نصائح أخرى

I once developed an app containing over 1 GB of static data. Luckily, when using "Build&Run", the app bundle is not removed from the device, but simply extracted in-place (giving rise to a lot of nasty issues when non-localized files do get localized, etc, but that's a different topic). Re-installing from the app store or using ad-hoc deployment does remove/clean the app bundle.

I abused this "feature" to only Build&Run the code, leaving out the data in subsequent debug builds, and putting it back in when making release builds.

If this trick still works I wouldn't know, but it's worth a try. To do this in a cleaner way, you could try to make 2 targets with identical settings, making the 100mb file member of only one of them.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top