使用CocoaPods post install hook将自定义路径添加到HEADER_SEARCH_PATHS

问题描述 投票:7回答:1

我正在尝试使用post install hook将$(PLATFORM_DIR)/ Developer / Library / Frameworks路径添加到Specta目标Header搜索路径。这显然不是至关重要的,但每次我进行“pod update”时手动添加此路径真的很烦人。

我得到了以下脚本:

post_install do |installer_representation|
  installer_representation.project.targets.each do |target|
      if target.name == 'Specta'
          target.build_configurations.each do |config|
             headers = config.build_settings['HEADER_SEARCH_PATHS']
             if headers
                 config.build_settings['HEADER_SEARCH_PATHS'] += ' $(PLATFORM_DIR)/Developer/Library/Frameworks'
             end
          end
      end
  end
end

如果有人能指出我正确的方向,我会很高兴,因为我真的被卡住了。

附:我已经注意到这条路径已经被CocoaPods添加了,但我仍然对如何做到这一点非常感兴趣,因为这些知识以后会很有用。谢谢!

ios xcode6 cocoapods post-install
1个回答
0
投票

在Podfile中定义一个方法:

def append_header_search_path(target, path)
    target.build_configurations.each do |config|
        # Note that there's a space character after `$(inherited)`.
        config.build_settings["HEADER_SEARCH_PATHS"] ||= "$(inherited) "
        config.build_settings["HEADER_SEARCH_PATHS"] << path
    end
end

然后调用post_install中的方法:

installer.pods_project.targets.each do |target|
    if target.name == "Specta"
        append_header_search_path(target, "$(PLATFORM_DIR)/Developer/Library/Frameworks")
    end
end
© www.soinside.com 2019 - 2024. All rights reserved.