Search code examples
iosios11

iOS11 AppIcon can't change


  • 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


Solution

  • 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