danielbeard danielbeard - 5 months ago 11
iOS Question

Copy dynamically created file into built app package

I have a file that I create in the

${SRCROOT}
folder of my iOS project when run. I want to copy this file so that when I build my app it is embedded in the package.

E.g.


  • When the app is built I create a file
    xyz.txt

  • I want this file to be copied to the app like a normal resource E.g.
    MyApp.app/xyz.txt



Here is what I have tried:

I have created a
Build Phase
->
Run Script
with the following:


cp "${SRCROOT}/xyz.txt ${DSTROOT}/xyz.txt


The above doesn't copy the file to where I want it to go. I have looked at this list of build variables but I'm not sure which one will work for my purpose.

How can I copy the created
xyz.txt
file to the main app bundle as a build phase?

Answer

I found the answer in this question: http://stackoverflow.com/a/7287596/1144632

I ended up using the following in my Run Script

cp "${SRCROOT}/xyz.txt" "${BUILT_PRODUCTS_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/xyz.txt"