Use same CFBundleVersion and CFBundleShortVersionString in all targets

前端 未结 7 2112
南旧
南旧 2020-12-31 08:31

I received the following email from Apple when I submit an app update:

We have discovered one or more issues with your recent delivery for \"Project

相关标签:
7条回答
  • 2020-12-31 09:08

    My solution is:

    For CFBundleShortVersionString:

    • Add a user-defined constant in your project settings

    • Name it $(CF_BUNDLE_SHORT_VERSION_STRING) and set it to your desired value

    • Set your version in your targets to $(CF_BUNDLE_SHORT_VERSION_STRING)

    • Repeat for all targets. Done!

    CFBundleVersion: you could do the same for CFBundleVersion, but somehow I wanted this value to be computed from my GIT repo commit count. I´ve done it like this:

    • Add a Pre-action to your main target. You access the shown dialog via Product > Scheme > Edit Scheme

    • Add a Post-action to your main target.

    • Add a new Command Line Tool target named BundleVersionUpdate and one named BundleVersionRevert

    • Navigate to your new BundleVersionUpdate target and add a new Run Script Build Phase

    • Paste the following
    \#!/bin/sh
    
    INFOPLIST="${SRCROOT}/MyApp/MyApp-Info.plist"
    INFOPLIST_WKAPP="${SRCROOT}/MyApp-WKApp/Info.plist"
    INFOPLIST_WKEXT="${SRCROOT}/MyApp-WKExt/Info.plist"
    
    PLISTCMD="Set :CFBundleVersion $(git rev-list --all|wc -l)"
    
    echo -n "$INFOPLIST" 
    | xargs -0 /usr/libexec/PlistBuddy -c "$PLISTCMD"
    
    echo -n "$INFOPLIST_WKAPP" 
    | xargs -0 /usr/libexec/PlistBuddy -c "$PLISTCMD"
    
    echo -n "$INFOPLIST_WKEXT" 
    | xargs -0 /usr/libexec/PlistBuddy -c "$PLISTCMD"
    
    • Navigate to your new BundleVersionRevert target and add a new Run Script Build Phase and paste this:
    \#!/bin/sh
    
    INFOPLIST="${SRCROOT}/MyApp/MyApp-Info.plist"
    INFOPLIST_WKAPP="${SRCROOT}/MyApp-WKApp/Info.plist"
    INFOPLIST_WKEXT="${SRCROOT}/MyApp-WKExt/Info.plist"
    
    PLISTCMD="Set :CFBundleVersion SCRIPTED"
    
    echo -n "$INFOPLIST" 
    | xargs -0 /usr/libexec/PlistBuddy -c "$PLISTCMD"
    
    echo -n "$INFOPLIST_WKAPP" 
    | xargs -0 /usr/libexec/PlistBuddy -c "$PLISTCMD"
    
    echo -n "$INFOPLIST_WKEXT" 
    | xargs -0 /usr/libexec/PlistBuddy -c "$PLISTCMD"
    
    • Enjoy!
    0 讨论(0)
提交回复
热议问题