首页 > 解决方案 > 如何在 CocoaPods post_install 挂钩中删除方案

问题描述

如何在post_install钩子中删除 CocoaPods 创建的方案?这有点令人费解,但这个方案正在破坏 Carthage为我的 SwiftMessages 库构建的版本。

根据这个线程,删除方案是可能的。但是,我查看了CocoaPods 参考资料,但没有找到办法。

更新

按照 Thiago Cruz 的建议,我在我的项目中添加了以下安装后挂钩。保持简单,我只是在 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不会还原此设置。

标签: cocoapods

解决方案


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

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

推荐阅读