iOS自动化打包上传App Store

最近iOS打包上传的任务比较多,有时候甚至每天多达近20次提交审核.这种无脑,机械,频繁,耗时的任务最适合搞成自动化来简化工作量.

所需工具如下

Xcodeproj

用来切换测试和生产证书

fastlane

打包上传TestFlight和App Store

fir

测试环境上传到fir,会有链接和二维码可以让测试直接扫码安装.

用Xcodeproj自动修改证书

    1. Installing Xcodeproj
1
[sudo] gem install xcodeproj
    1. 工程根目录新建.rb文件

执行ruby xxx.rb 将会自动修改证书为com.xxx.yyy xxx_appStore,省的每次都要从测试证书修改为生产证书,至少能节省10秒钟的时间.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require 'xcodeproj'
project_path = './xxx.xcodeproj' # 工程的全路径
project = Xcodeproj::Project.open(project_path)
puts 'ruby开始修改证书id和描述文件...'

project.targets.each do |target|
target.build_configurations.each do |config|
# 修改描述文件的id,值为id而不是名称
config.build_settings['CODE_SIGN_IDENTITY'] = 'Apple Distribution'
config.build_settings['CODE_SIGN_IDENTITY[sdk=iphoneos*]'] = 'Apple Distribution'
config.build_settings['CODE_SIGN_STYLE'] = 'Manual'

config.build_settings['DEVELOPMENT_TEAM'] = '4LJHGGLLHHB'

config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = 'com.xxx.yyy'
config.build_settings['PROVISIONING_PROFILE_SPECIFIER'] = 'xxx_appStore'
end
end

project.save
puts '修改完成...'

project.targets.each do |target|
target.build_configurations.each do |config|
puts '修改之后描述文件的id'
puts config.build_settings['PROVISIONING_PROFILE']

# puts '修改之后证书签名标识'
puts config.build_settings['CODE_SIGN_IDENTITY']

# 工程的标识
puts '修改之后工程的id'
puts config.build_settings['PRODUCT_BUNDLE_IDENTIFIER']
end
end

用fastlane自动打包上传App Store

证书修改好了,可以在xcode里面点product-archive,经过漫长的等待,然后下一步下一步.耗费了青春,掉落了头发.一个有追求的程序员,怎么能忍受这么无聊的事情.

上大招 fastlane 直达文档

1
2
3
4
5
6
7
xcode-select --install

sudo gem install fastlane -NV

fastlane init

fastlane release

有图有真相,我装完是这样,你装完也是这样.

fastlane整体截图
fastfile截图
直接 fastlane release 就完事了

上传到fir用来内测试

fir官网

fir.im fastlane 插件

github教程

完事之后就像这样

fastlane+App Store+fir

直接fastlane beta就完事了