Different app-name depending on configuration when app-name is localized in InfoPlist.strings

后端 未结 1 1620
挽巷
挽巷 2021-02-04 13:38

We use a setup with different plists for each configuration. Like this: Target-Info-Dev.plist, Target-Info-Beta.plist...

This way our configurations could have

相关标签:
1条回答
  • 2021-02-04 14:21

    Better Solution

    1. Edit Info.plist, set CFBundleDisplayName's value to a variable named something like $(MY_DISPLAY_NAME)

    1. Open 'Build Settings' tab of the project or target, add a key named MY_DISPLAY_NAME under User-Defined section(you need scroll to the bottom to find this section), then just expand the newly-added key, and set any name for each configuration as you wish.

    When building your project, every variable in the Info.plist will be replaced to its value.

    The solution is much simpler than the original one.

    Original Solution

    I had the same requirement in my project, and then I found your question, and at last I solved it. Edit your projects' scheme, add pre-action and post-action script to execute your change. Like this,

    Step 1. change app name in Build's Pre-actions

    str=""
    if [ "${CONFIGURATION}" == "Debug" ];then
        str="dev"
    elif [ "${CONFIGURATION}" == "AdhocDevelopment" ];then
        str="dev"
    elif [ "${CONFIGURATION}" == "AdhocDistribution" ];then
        str="adhoc"
    elif [ "${CONFIGURATION}" == "DailyBuild" ];then
        str="rdm"
    fi
    perl -pi -e "s/appName[^<]*/appName${str}/g" ${PROJECT_DIR}/smd/Info.plist
    

    Step 2. Restore app name in Build's Post-actions

    perl -pi -e "s/appName[^<]*/appName/g" ${PROJECT_DIR}/smd/Info.plist
    echo ${PROJECT_DIR}/${INFOPLIST_FILE} > ~/tmp.txt; rm -f ~/tmp.txt
    

    Something to explain: Debug/AdhocDevelopment/AdhocDistribution/DailyBuild are your projects' configuration names; ${CONFIGURATION} is predefined by Xcode; perl is preferable to awk and sed, which are all pre-installed on every mac OS X.

    By the way, what I have done is changing appName in Info.plist, you can change your infoPlist.strings. In this way, you just need a single Info.plist file.

    0 讨论(0)
提交回复
热议问题