我为我的Xcode项目添加了一个配置(adhoc)(假设名称为Flurry),我想在该配置中添加GCC_PREPROCESSOR_DEFINITIONS
,如DEBUG。我通过pro_install hook执行了此操作。我添加了以下代码:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if config.name == "Adhoc"
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << "ADHOC"
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << "ADHOC=1"
end
end
end
端
因为我使用的是cocoapods 0.38.2,所以我需要使用pods_project
代替project
。
该代码适用于由cocoapods生成的目标,如AFNetworking,Pods-Flurry和所有第三方框架。但它没有对我的项目Flurry做任何改动。所以当我使用以下代码时,预处理器marco ADHOC 没有工作:
#ifdef ADHOC
NSLog(@"do something here");
#endif
那么,如何使用post_install hook添加预处理器marco我的adhoc配置。
BTW,下面的代码适用于旧版本,如0.37.1:
pods_project和project
只有一个区别post_install do |installer|
installer.project.targets.each do |target|
target.build_configurations.each do |config|
if config.name == "Adhoc"
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << "ADHOC"
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << "ADHOC=1"
end
end
end
端