问题是:CocoaPods为我的项目生成xcconfig
文件,我希望将xcconfig
文件作为依赖项包含在其中。我可以在post_install
钩子中做到吗?
我只发现XCBuildConfiguration有build_settings
哈希,但据我所知,我只能添加或更改密钥,而不包含带有该哈希的语句。
答案 0 :(得分:0)
按照this answer的说明,我可以更新xcconfig
,并使用此代码将我的xcconfig
文件包含在已生成的广告单元中:
post_install do |installer|
installer.pods_project.targets.each do |target|
next unless target.name.include?("Pods-CNISDK")
puts "Updating #{target.name}"
target.build_configurations.each do |config|
xcconfig_path = config.base_configuration_reference.real_path
# read from xcconfig to build_settings dictionary
build_settings = Hash[*File.read(xcconfig_path).lines.map{|x| x.split(/\s*=\s*/, 2)}.flatten]
# write build_settings dictionary to xcconfig
File.open(xcconfig_path, "w") do |file|
file.puts "#include \"../configurations/Warnings.xcconfig\"\n"
build_settings.each do |key,value|
file.puts "#{key} = #{value}"
end
end
end
end
end