Can Xcode include application resource files that

2019-04-15 13:03发布

问题:

I have a bunch of content files for my iPhone app that I generate via shell script. It takes way too long to be a part of the Xcode build process, so I run it periodically.

I don't want to have to continually add these files to my Xcode project in order to get them included my app resources folder. Is there a way to get Xcode to copy the contents of a folder into the app resources at build time? (It'd be a bonus if I could specify other locations, such as the approot documents folder.)

I tried adding a new 'Copy Files Build Phase' to my target, but that didn't seem to work. This seems like a common problem, but I couldn't find anything about it here.

-- Edit (What I did)

Per Jasarien and cdespinosa's suggestions, I did the following in a build script. I decided not to copy to the destination, because that would only work when using the simulator, I don't think that'll work when deploying to a device.

cp -rf "$PROJECT_DIR/mystuff" "$CONFIGURATION_BUILD_DIR/$CONTENTS_FOLDER_PATH/"

-- Edit 2

This doesn't appear to get files onto my iPhone. Any ideas?

回答1:

You can setup a Run Script build phase in your app's target. Write the script so that it copies the resources into the app bundle.



回答2:

This is the path i use for output:

${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}

Just copy your files in that directory, it's the bundle (simulator or device).

You can also take a look at my answer here : how to set up a Xcode build rule with a variable output file list?