Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The best way I found to add any number of files to my xcode project (and make some processing) is to write a little php script. The script can simply copy files into the bundle. The tricky part is the integration with xcode. It took me some time to find a clean way. (You can use the script language you like with this method).</p> <p>First, use "Add Run Script" instead of "Add Copy File"</p> <p>Shell parameter:</p> <pre><code>/bin/sh </code></pre> <p>Command parameter:</p> <pre><code>${SRCROOT}/your_script.php -s ${SRCROOT} -o ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH} exit $? </code></pre> <p><a href="http://www.hostingpics.net/viewer.php?id=150511ScreenShot20130320at24500PM.png" rel="nofollow">(screenshot in xcode)</a></p> <p>${SRCROOT} is your project directory.</p> <p>${CONFIGURATION(...) is the bundle directory. Exactly what you need :)</p> <p>This way, your script return code can stop xcode build (use die(0) for success and die(1) for failures) and the output of script will be visible in xcode's build log.</p> <p>Your script will look like that: (don't forget chmod +x on it)</p> <pre><code>#!/usr/bin/php &lt;?php error_reporting(E_ALL); $options = getopt("s:o:"); $src_dir = $options["s"]."/"; $output_dir = $options["o"]."/"; // process_files (...) die(0); ?&gt; </code></pre> <hr> <p><strong>BONUS</strong>: here my 'add_file' function.</p> <ul> <li>Note the special treatment for PNG (use apple's png compression)</li> <li>Note the filemtime/touch usage to prevent copy files each times.</li> </ul> <p>l</p> <pre><code>define("COPY_PNG", "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/copypng -compress"); function add_file_to_bundle($output_dir, $filepath) { // split path $path_info = pathinfo($filepath); $output_filepath = $output_dir.$path_info['basename']; // get file's dates of input and output $input_date = filemtime($filepath); $output_date = @filemtime($output_filepath); if ($input_date === FALSE) { echo "can't get input file's modification date"; die(1); } // skip unchanged files if ($output_date === $input_date) { //message("skip ".$path_info['basename']); return 0; } // special copy for png with apple's png compression tool if (strcasecmp($path_info['extension'], "png") == 0) { //message($path_info['basename']." is a png"); passthru(COPY_PNG." ".escapeshellarg($filepath)." ".escapeshellarg($output_filepath), $return_var); if ($return_var != 0) die($return_var); } // classic copy else { //message("copy ".$path_info['basename']); passthru("cp ".escapeshellarg($filepath)." ".escapeshellarg($output_filepath), $return_var); if ($return_var != 0) die($return_var); } // important: set output file date with input file date touch($output_filepath, $input_date, $input_date); return 1; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload