如何在 CocoaPods post_install hook 中删除一个 scheme

How to delete a scheme in CocoaPods post_install hook

如何删除CocoaPods在post_install hook中创建的scheme?这有点复杂,但这个方案是 breaking Carthage builds 用于我的 SwiftMessages 库。

根据 this thread, deleting schemes is possible. However, I've looked through the CocoaPods reference 并没有找到方法。

更新

根据 Thiago Cruz 的建议,我将以下 post 安装挂钩添加到我的项目中。为简单起见,我只是吹走了 pods 项目中的所有用户和共享数据。

post_install do |installer|
  # Blow away schemes – the schemes created by CocoaPods break Carthage builds
  # because they incluede a SwiftMessages framework that Carthage picks
  # over the main SwiftMessages framework. The SwiftMessages framework that gets
  # picked is configured for an app extension and doesn't work correctly in an app.
  File.directory?(path)
  [
    "#{installer.sandbox.root}/Pods.xcodeproj/xcuserdata",
    "#{installer.sandbox.root}/Pods.xcodeproj/xcshareddata"
  ].each { |path|
    if File.directory?(path)
      FileUtils.remove_dir(path)
    end
  }
end

除此之外,我还必须打开 pods 项目并在方案管理对话框中禁用“自动创建方案”。值得注意的是 pod install 不会恢复此设置。

不确定要删除哪些 .xcscheme 文件,但在 post_install 挂钩中,您可以访问项目的根目录以及 /Pods 根目录。您可以glob找到文件并手动删除它。

post_install do |installer|
  puts "#{installer.config.installation_root}"
  puts "#{installer.sandbox.root}"
end