You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何根据TestFlight已批准iOS版本递增版本号?

解决TestFlight已批准版本号最后一位自动递增的问题

我之前刚好碰到过完全一样的困扰——Fastlane自带的increment_version_number只能本地改Info.plist,get_version_number又没法灵活拆分版本号递增最后一位。后来结合Fastlane的Spaceship工具搞定了,下面是具体的实现步骤:

1. 先确保Spaceship能正常访问App Store Connect

首先得让Fastlane能和App Store Connect通信,你可以用fastlane spaceauth登录授权,或者配置App Store Connect API密钥(更适合CI环境),这一步是基础,不然拿不到TestFlight的版本数据。

2. 写一个自定义Fastlane Lane

在你的Fastfile里加个自定义lane,比如叫increment_testflight_patch_version,代码如下:

lane :increment_testflight_patch_version do
  # 替换成你自己的App Bundle ID
  target_bundle_id = "com.your.app.bundle.id"
  app = Spaceship::ConnectAPI::App.find(target_bundle_id)

  # 过滤出TestFlight上已批准的构建,取最新的版本号
  approved_builds = app.builds.select { |build| build.processing_state == "approved" }
  latest_approved_version = approved_builds.sort_by { |b| b.version }.last.version

  # 拆分版本号,递增最后一位
  version_components = latest_approved_version.split(".").map(&:to_i)
  version_components[-1] += 1
  new_version = version_components.join(".")

  # 更新本地Info.plist的版本号
  increment_version_number(version_number: new_version)

  puts "🎉 版本号更新完成:#{latest_approved_version} → #{new_version}"
end

3. 关键逻辑解释

  • 获取已批准版本:通过Spaceship::ConnectAPI直接从App Store Connect拉取应用的所有构建,筛选出状态为approved的(就是已经通过审核可以在TestFlight分发的版本),然后排序拿到最新的那个版本号。
  • 版本号拆分与递增:把版本号按.拆成数组,转成整数后给*最后一位(Patch版本)*加1,再拼回去——不管是2.4.1这种三位版本,还是1.0这种两位的都能完美处理。
  • 同步到本地:最后调用Fastlane自带的increment_version_number,传入新生成的版本号,自动更新Info.plist,不用手动改文件了。

4. 额外优化建议

  • 如果你的项目需要区分版本号(version number)和构建号(build number),可以在这个lane里再加一行increment_build_number,或者自定义构建号的递增规则;
  • 要是有多个target,也可以给increment_version_number加上target: "YourTargetName"参数指定目标。

现在每次要上传TestFlight前,直接跑fastlane increment_testflight_patch_version,就能自动把版本号从TestFlight最新已批准的2.4.1变成2.4.2,省心多了!

内容的提问来源于stack exchange,提问作者Igor Vlasuyk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 20:39:09