在所有目标中使用相同的CFBundleVersion和CFBundleShortVersionString [英] Use same CFBundleVersion and CFBundleShortVersionString in all targets

查看:2123
本文介绍了在所有目标中使用相同的CFBundleVersion和CFBundleShortVersionString的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在提交应用更新时收到Apple发来的以下电子邮件:

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". Your delivery was successful, but you may wish to correct the following issues in your next delivery:

CFBundleVersion Mismatch - CFBundleVersion扩展名为
的值'1''Project.app/PlugIns/ProjectTodayExtension.appex'不与
匹配其包含iOS
应用程序'Project.app'的CFBundleVersion值'985'。

CFBundleVersion Mismatch - The CFBundleVersion value '1' of extension 'Project.app/PlugIns/ProjectTodayExtension.appex' does not match the CFBundleVersion value '985' of its containing iOS application 'Project.app'.

CFBundleShortVersionString不匹配 - 扩展'Project.app/PlugIns/ProjectTodayExtension.appex'的CFBundleShortVersionString
值'1.0'不是
匹配其包含
iOS应用程序'Project.app'的CFBundleShortVersionString值'2.1.6'。

CFBundleShortVersionString Mismatch - The CFBundleShortVersionString value '1.0' of extension 'Project.app/PlugIns/ProjectTodayExtension.appex' does not match the CFBundleShortVersionString value '2.1.6' of its containing iOS application 'Project.app'.

在您更正问题后,您可以使用Xcode或Application
Loader将新的二进制文件上传到iTunes Connect。

After you’ve corrected the issues, you can use Xcode or Application Loader to upload a new binary to iTunes Connect.

有什么方法可以使用相同的 CFBundleVersion CFBundl所有目标中的eShortVersionString 都可以防止这种情况发生?

Is there any way of use the same CFBundleVersion and CFBundleShortVersionString in all targets to prevent this?

推荐答案

我的解决方案是:

对于 CFBundleShortVersionString


  • 项目中添加用户定义的常量设置

  • Add a user-defined constant in your project settings


  • 将其命名为 $(CF_BUNDLE_SHORT_VERSION_STRING)并将其设置为所需的值

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


  • 设置你的版本在你的目标中 $(CF_BUNDLE_SHORT_VERSION_STRING)

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


  • 对所有目标重复。 完成

  • Repeat for all targets. Done!

CFBundleVersion :您可以对 CFBundleVersion 执行相同操作,但不知何故,我希望根据我的GIT repo提交计算来计算此值。我这样做了:

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.


  • 添加新命令行工具目标名为 BundleVersionUpdate ,一个名为 BundleVersionRevert

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


  • 导航到新的 BundleVersionUpdate 目标并添加新的运行脚本构建阶段

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


  • 粘贴以下内容


\#!/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"





  • 导航到新的 BundleVersionRevert 目标并添加新的运行脚本构建阶段并粘贴:

    • 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"
      





      • 享受!

      • 这篇关于在所有目标中使用相同的CFBundleVersion和CFBundleShortVersionString的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆