ios - 在 faSTLane 中运行健身房脚本时如何获取用户选择的方案?

标签 ios fastlane

我已将 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/

相关文章:

iphone - 设置 UITableViewCell 文本的宽度

ios - 有没有办法让 Apple App Store 验证框架?

ios - 当 segue 完成时,NSString 被删除

android - FaSTLane 安卓 :Gradle sync failed: Could not find method screengrabVersion() for arguments

使用 FaSTLane 翻译插件进行 iOS 本地化

ios - Xcode 在 View 可见后加载缓慢的东西

ios - 粒子过滤器 iOS 实现失败

ios - Xcode 签名有效,但 faSTLane 无效

android - FaSTLane gradle 命令 - 未传递属性

android - 是否可以从Google Play商店或 “symlink”中检索使用faSTLane生成的发行说明,以便可以在应用程序中显示它?