Cocoapod:使用post install hook重新定义预处理宏

时间:2015-02-27 10:45:55

标签: ios xcode cocoapods

我想更新我的pod,让用户激活/停用某个功能。

为此,我在podspec中添加了预处理器宏:

s.xcconfig         = { 'GCC_PREPROCESSOR_DEFINITIONS' => 'FEATURE=1' }

现在,对于用户而言(正如我所理解的)正确的做法应该是使用podfile中的安装后挂钩来更改FEATURE的定义

post_install do |installer_representation|
  installer_representation.project.targets.each do |target|
    if target.name == "Pods-MyPod"
      target.build_configurations.each do |config|
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'FEATURE=0']
      end
    end
  end
end

但它根本没有做任何事情...... FEATURE值仍为1

我做错了吗?

编辑: 我确实看过这个answer,但没有用。

1 个答案:

答案 0 :(得分:4)

最后,我发现了一个有效的版本。

post_install do |installer_representation|
  installer_representation.pods_project.targets.each do |target|
    if target.name == "Pods-MyPod"
      target.build_configurations.each do |config|
      config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = ['COCOAPODS=1', 'FEATURE=0']
      end
    end
  end
end
相关问题