想著消除工程里的一些警告,就研究了下cocoapod的一些功能,
我們可以使用inhibit_all_warnings!來忽略pod里引用的第三方庫的警告
然后還有一些其他的警告:
最常見的警告是Validate Project Settings

image1.png
這其實(shí)是
iOS Deployment Target設(shè)置在作怪在工程內(nèi)選擇
DTCoreText Target查看
image2.png
這里iOS Deployment Target 4.3跟我們項(xiàng)目最低支持8.0系統(tǒng)的配置不一樣,
我在Podfile里已經(jīng)配置了platform :ios, '8.0',是什么導(dǎo)致這樣的情況呢?
我們?nèi)ithub上看看DTCoreText/DTCoreText.podspec

image.png
第四行
spec.platforms = {:ios => '4.3', :tvos => '9.0' }是只DTCoreText支持iOS4.3以上的系統(tǒng),cocoapod根據(jù)這個(gè)設(shè)置iOS Deployment Target不知道是bug還是feature
點(diǎn)擊 image1.png里Update to recommended settings XCode會(huì)彈出推薦配置

image.png
選擇
Perform Changesxcode會(huì)把所有不匹配的
iOS Deployment Target設(shè)置一遍。但是這樣每次pod install 一次后得手動(dòng)設(shè)置未免有些繁瑣。下面給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設(shè)置一些自定義的編譯選項(xiàng):
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跟實(shí)際的key:IPHONEOS_DEPLOYMENT_TARGET不一樣,獲取真實(shí)key的方式的方式很簡單:
如 image2.png 選中藍(lán)色iOS Deployment Target 按下復(fù)制(command + c)
然后粘貼到空白處,就能看到真實(shí)的key:
//:configuration = Debug
IPHONEOS_DEPLOYMENT_TARGET = 8.0
//:configuration = Release
IPHONEOS_DEPLOYMENT_TARGET = 8.0
//:completeSettings = some
IPHONEOS_DEPLOYMENT_TARGET
如果你想只針對Release設(shè)置,那么這樣:
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
最后別忘了執(zhí)行pod install
enjoy!