我已将 faSTLane 添加到我的 iOS 项目中以创建 .ipa
使用以下脚本我可以创建 ipa。
desc "Generate .ipa"
lane :createipa do
gym(clean: true, export_method: ENV["EXPORT_METHOD"], output_directory: ENV["DIRECTORY"])
end
gym 还有另外 2 个属性,一个是 scheme ,它与不同的方案以及您想要从中创建 ipa 的属性相关,另一个是 output_name ,它是IPA 的名称。 现在,当我在没有方案的情况下使用此脚本时,它要求我在运行时选择方案,我想在运行时将用户输入方案保存到变量并将其设置为output_name,有什么办法吗?
最佳答案
既然您正在寻找用户输入,为什么不在运行 faSTLane
时将方案名称传递给脚本呢?像这样:
bundle exec faSTLane createipa 方案: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 捆绑执行 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
关于ios - 在 faSTLane 中运行健身房脚本时如何获取用户选择的方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44644139/