0

I'm having trouble with the 'Run Script' in the Xcode IDE. I'm able to download a file from a server using this script below, straight into a directory in Xcode, which can be viewed, by way of right clicking on the folder in the IDE where the download has been sent to, however although it appears here, its not appearing in the 'Copy Bundle Resources' nor in the Xcode resources folder, so when trying to pull this file into the code, I get file doesn't exist.

I'm aware of how to add the file manually(+), however this would be better if it run's automatically in the script.

Can anyone help with this Bash Script below, I've tried to copy (cp) to ${PRODUCTS_DIR} and ${BUILT_PRODUCTS_DIR} but its not copying over for some reason. I'm able to (mv) move the file but still this does appear in the 'Copy Bundle Resources'? Anyone got any clues to this? Thanks in advance.

fileToDownload=$(ssh $Username@server1 ls -t /doc_test_control/the_test_foler/myFile.txt)
echo "File to download: $fileToDownload"


scp $Username@server1:$fileToDownload "${SRCROOT}/Mobile-App-iOS/Test_Foler/"
echo "File downloaded to : ${SRCROOT}/"

mv "${SRCROOT}/Mobile-App-iOS/Test_Foler/""* "${BUILT_PRODUCTS_DIR}"

ls -l "${SRCROOT}/Mobile-App-iOS/Test_Foler/"
echo "DONE"
Jonas
  • 474
  • 3
  • 17

1 Answers1

1

It looks like you need to copy the downloaded file inside the Bundle using bash commands in the Run Script phase itself. Please use the following script to copy the resource to the bundle.

cp downloadedFile ${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/

UNLOCALIZED_RESOURCES_FOLDER_PATH is nothing but app path itself. Please see its value in Build logs.

export UNLOCALIZED_RESOURCES_FOLDER_PATH=TestProject.app

I tested this with my local file in Desktop folder and found it to be working.

You cannot use "Copy Bundle Resource" phase to copy the downloaded file at compile time. Because, to use "Copy Bundle Resource", it has to be added to the Target which is not possible when it is downloaded during compile time.

Anand
  • 1,820
  • 2
  • 18
  • 25
  • Unfortunately this works like you say locally, however this still doesn't copy into the IDE directory folder that I would like. When copying and checking the Build logs, I can see that is tried to copy and displays the message 'cp [-R[-H | -L | -P]]" etc. I have tried cp -R still not working, could you please explain what the 'export' should be doing? – Jonas Apr 23 '19 at 10:16