9
  • Xcode 9 beta 6
  • iOS 11 beta 10

    I want package application with custom App icon , so I try to replace AppIcon.png files at DerivedData (/Users/XXX/Library/Developer/Xcode/DerivedData/project/Build/Products/Debug-iphoneos/xxx.app)

    It worked at iOS 10, but doesn't work at iOS 11

    Can anybody solve it?

    Thanks for advance

6
  • why in derived data? Don't you have the code? If you don't have then change in IPA file by creating it is a Zip file, add your new images and again convert a zip to IPA file. In last do code resign by any tool say Fastlane.
    – Gagan_iOS
    Sep 8, 2017 at 10:17
  • I have code , but I creat a new custom icon with buildversion by shell scrip, and I try to replace it, and failed at iOS 11 Sep 8, 2017 at 10:21
  • 1
    perfect you have code & icons as well. Now check where App icons are located in your code. Should be in imageassets folder. Open assets folder select App Icon & drag-drop your new icon files.
    – Gagan_iOS
    Sep 8, 2017 at 10:24
  • 1
    I did know how to change app icon through Images.xcassets, but I don't have new pic as icon, the pic generating by script when I build my application Sep 8, 2017 at 10:28
  • @Paladinfeng, you may be aware of the compiler hashes the files during building the package (i.e. debug or release), therefore you cannot just replace a file in the bundle after that – your script must run before it, or you need to change to icon in the project before compilation.
    – holex
    Sep 8, 2017 at 10:28

1 Answer 1

6

I have found a solution. I change app icons in the source .xcasset folder, not in Derived Data (using ImageMagick). So, here is my script:

#!/bin/bash

IFS=$'\n'
BASE_ICONS_DIR=$(find ${SRCROOT}/${PRODUCT_NAME} -name "AppIcon.appiconset")
IFS=$' '
CONTENTS_JSON="${BASE_ICONS_DIR}/Contents.json"

version=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${INFOPLIST_FILE}"`
# The next line adds special suffix, necessary in my project
version="${version/'$(VERSION_SUFFIX)'/$VERSION_SUFFIX}"

function tag() {
    export PATH=$PATH:/usr/local/bin:/opt/boxen/homebrew/bin/
    ICON_PATH=$1

    width=`identify -format %w ${ICON_PATH}`
    [ $? -eq 0 ] || exit 1

    height=$((width * 30 / 100))

    if [ "${CONFIGURATION}" != "AppStore" ]; then
       convert -background '#0008' \
       -fill white -gravity center \
       -size ${width}x${height} \
       caption:"${version}" \
       "${ICON_PATH}" +swap -gravity south -composite "${ICON_PATH}" || exit 1
    fi
}

ICONS=(`grep 'filename' "${CONTENTS_JSON}" | cut -f2 -d: | tr -d ',' | tr -d '\n' | tr -d '"'`)

ICONS_COUNT=${#ICONS[*]}

IFS=$'\n'

for (( i=0; i<ICONS_COUNT; i++ )); do
    tag "$BASE_ICONS_DIR/${ICONS[$i]}"
done

This script is executed before Copy Bundle Resources. After executing app icons are changed, so I need to revert changes with additional Run Script as a last Build Phase:

if [ "${CONFIGURATION}" != "AppStore" ]; then
   IFS=$'\n'
   git checkout -- `find "${SRCROOT}/${PRODUCT_NAME}" -name AppIcon.appiconset -type d`
fi

My Build Phases looks like this:

My Build Phases looks like this

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.