如何在fastlane中运行健身脚本时获得用户选择的方案?
问题描述:
我已经在我的iOS项目中添加了fastlane以创建.ipa如何在fastlane中运行健身脚本时获得用户选择的方案?
使用以下脚本我可以创建ipa。
desc "Generate .ipa"
lane :createipa do
gym(clean: true, export_method: ENV["EXPORT_METHOD"], output_directory: ENV["DIRECTORY"])
end
还有其他2个属性的健身房,一个是方案这是关系到不同的方案,你想创建IPA的一个,另一个是output_name中这是IPA的名称。 现在,当我使用这个脚本没有方案,它问我在运行时选择的方案,我想在运行时将用户输入方案保存到一个变量,并将其设置为output_name,有没有什么办法可以做那?
答
既然您正在寻找用户输入,那么当您运行fastlane
时,为什么不只是将方案名称传递给脚本?像这样:
bundle exec fastlane createipa scheme:MySchemeName
并修改Fastfile
是:
desc "Generate .ipa"
lane :createipa do |options|
gym(
clean: true,
export_method: ENV["EXPORT_METHOD"],
output_directory: ENV["DIRECTORY"],
scheme: options[:scheme]
)
end
或者,你可以将其保存为ENV
项:
XCODE_SCHEME=MySchemeName bundle exec fastlane
要回答直接提问,使用此代码
desc 'Generate the ipa based on the scheme selected by the user'
lane :createipa do
glob_pattern = 'MyApp/MyApp.xcodeproj/**/*.xcscheme'
schemes = Dir[glob_pattern].map do |scheme_filepath|
File.basename(scheme_filepath)
end
prompt_text = 'Select a scheme:\n'
schemes.each_index do |index|
prompt_text << " #{index}. #{schemes[index]}\n"
end
prompt_text << '> '
print prompt_text
selected_scheme_index = gets.to_i
selected_scheme = schemes[selected_scheme_index]
puts "Selected Scheme: #{selected_scheme}"
ipa_output_name "#{selected_scheme}.ipa"
gym(
clean: true,
export_method: ENV['EXPORT_METHOD'],
output_directory: ENV['DIRECTORY'],
scheme: selected_scheme,
output_name: ipa_output_name
)
end
_personally_,我宁愿以相同的方式传递所有这些参数。可以作为车道的选项,或者全部作为“ENV”条目。 –
好吧,问题是我不知道方案名称,所以我不能在'''fastlane createipa'''后面添加它。当我运行'''fastlane createipa'''时,因为我没有选择方案,它显示了我的方案列表,并要求我选择一个,这就是我想说的用户输入,并把它作为** output_name *** – Mina
我很困惑。您可以通过打开Xcode并查看方案或导航到项目包“MyProject.xcodeproj/xcsharedata/xcschemes/SchemeName.xcscheme”(或者,而不是'xcshareddata','xcuserdata')来轻松查看这些方案。你能详细说明当你运行命令时你为什么不知道该方案是什么吗?如果我明白什么是问题,我可以帮助你。 –