在公司经历过同时需要添加多个设备并更新profile,幸得有spaceship相助,写了个脚本UpdateProfile.rb:
require "spaceship"
Spaceship.login('APPLE ID', 'password')
#参数传入true表示需要新增设备,例如:ruby UpdateProfile.rb true
if ARGV[0] == "true"
file = File.open("multiple-device-upload-ios.txt") #文本文件里录入的udid和设备名用tab分隔
file.each do |line|
arr = line.strip.split("\t")
device = Spaceship.device.create!(name: arr[1], udid: arr[0])
puts "add device: #{device.name} #{device.udid} #{device.model}"
end
devices = Spaceship.device.all
profiles = Array.new
profiles += Spaceship.provisioning_profile.development.all
profiles += Spaceship.provisioning_profile.ad_hoc.all
profiles.each do |p|
puts "Updating #{p.name}"
p.devices = devices
p.update!
end
end
dic = { "XXXAdHoc" => "773086ad-6b7b-4e57-85b7-08b577308e91.mobileprovision",
"XXXDevelop" => "a7a85aa7-f359-4415-a8ed-3dacc31ea448.mobileprovision" }
downloadProfiles = Array.new
downloadProfiles += Spaceship.provisioning_profile.development.all
downloadProfiles += Spaceship.provisioning_profile.ad_hoc.all
downloadProfiles.each do |p|
puts "Downloading #{p.name}"
fileName = dic[p.name]
File.write("/Users/ray/Library/MobileDevice/Provisioning Profiles/#{fileName}", p.download)
end
脚本说明:
- APPLE ID和password替换为自己的帐号
脚本文件同目录下需要一个multiple-device-upload-ios.txt文件,文件里录入的udid在前,设备名在后,用tab分隔;如:
udid1 ray's iPhone udid2 jun's iPhone
- dic字典存放的是profile名及其对应的保存到电脑里的mobileprovision名
- 最后一句代码File.write记得把ray改成自己的Users路径名
- 新增设备执行:
ruby UpdateProfile.rb true
- 若只需要更新profile文件则执行:
ruby UpdateProfile.rb
收工搞定