cocoapod自定义BuildSetting设置
2018-08-23 本文已影响413人
小杰杰杰
想着消除工程里的一些警告,就研究了下cocoapod的一些功能,
我们可以使用inhibit_all_warnings!
来忽略pod里引用的第三方库的警告
然后还有一些其他的警告:
最常见的警告是Validate Project Settings
![](https://img.haomeiwen.com/i263551/a92d69cd4b513ff4.png)
这其实是
iOS Deployment Target
设置在作怪在工程内选择
DTCoreText Target
查看![](https://img.haomeiwen.com/i263551/7f43fb80981f879c.png)
这里iOS Deployment Target 4.3
跟我们项目最低支持8.0
系统的配置不一样,
我在Podfile
里已经配置了platform :ios, '8.0'
,是什么导致这样的情况呢?
我们去Github上看看DTCoreText/DTCoreText.podspec
![](https://img.haomeiwen.com/i263551/0f452994787497b8.png)
第四行
spec.platforms = {:ios => '4.3', :tvos => '9.0' }
是只DTCoreText支持iOS4.3以上的系统,cocoapod根据这个设置iOS Deployment Target
不知道是bug还是feature
点击 image1.png
里Update to recommended settings
XCode会弹出推荐配置
![](https://img.haomeiwen.com/i263551/30119f516f3f5f46.png)
选择
Perform Changes
xcode会把所有不匹配的
iOS Deployment Target
设置一遍。但是这样每次pod install 一次后得手动设置未免有些繁琐。下面给cocoapod添加自定义配置:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '8.0'
end
end
end
也可以给cocoapod设置一些自定义的编译选项:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['STRIP_INSTALLED_PRODUCT'] = 'YES'
config.build_settings['STRIP_STYLE'] = 'non-global'
config.build_settings['DEPLOYMENT_POSTPROCESSING'] = 'YES'
end
end
end
Xcode Build Settings显示的iOS Deployment Target
跟实际的key:IPHONEOS_DEPLOYMENT_TARGET
不一样,获取真实key的方式的方式很简单:
如 image2.png
选中蓝色iOS Deployment Target
按下复制(command + c)
然后粘贴到空白处,就能看到真实的key:
//:configuration = Debug
IPHONEOS_DEPLOYMENT_TARGET = 8.0
//:configuration = Release
IPHONEOS_DEPLOYMENT_TARGET = 8.0
//:completeSettings = some
IPHONEOS_DEPLOYMENT_TARGET
如果你想只针对Release设置,那么这样:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
if config.name == "Release"
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '8.0'
end
end
end
end
其他例子
if config.name == "Debug" then
//do something
elsif config.name == "Release" then
//do something
end
最后别忘了执行pod install
enjoy!