Cocoapod的安装后直接获得主要项目

时间:2018-10-03 13:39:07

标签: ruby cocoapods

在为touchesMoved创建CocoaPod Podspec时,我需要安装要在主项目中的所有其他vendored_framework之后运行的shell脚本。我发现执行此操作的唯一方法是从build_phases中获取.xcodeproj文件的目录。

Podfile

鉴于post_install do |installer| project_name = Dir.glob("*.xcodeproj").first project = Xcodeproj::Project.open(project_name) project.targets.each do |target| inject_shell_script_build_phase(target) end project.save end pod install正在运行,并且显然已经具有此信息,这似乎很荒谬。有没有一种方法可以直接获取pod update引用,而不必对项目文件名进行全局或硬编码?

2 个答案:

答案 0 :(得分:1)

https://guides.cocoapods.org/syntax/podfile.html

installer.pods_project

post_install do |installer|
  project = installer.pods_project

  project.targets.each do |target|
    inject_shell_script_build_phase(target)
  end

  project.save
end

https://www.rubydoc.info/gems/cocoapods/Pod/Installer#pods_project-instance_method https://www.rubydoc.info/gems/cocoapods/Pod/Project继承自https://www.rubydoc.info/gems/xcodeproj/Xcodeproj/Project


可以迭代* .xcodeproj

post_install do |installer|
  installer.aggregate_targets.each do |target|
    user_project = target.user_project

    puts "#{user_project.path}"
  end
end

https://www.rubydoc.info/gems/cocoapods/Pod%2FInstaller%3Aaggregate_targets https://www.rubydoc.info/gems/cocoapods/Pod/AggregateTarget

答案 1 :(得分:0)

这应该可以解决问题...注意 post_integrate 钩子。否则我的更改将被覆盖(被忽略?),除非我通过直接打开文件进行更改。

post_integrate do |installer|
  project =  installer.aggregate_targets[0].user_project
  project.targets.each do |target|
    inject_shell_script_build_phase(target)
  end
  project.save
end