cocoapod自定義BuildSetting設(shè)置

想著消除工程里的一些警告,就研究了下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.pngUpdate to recommended settings XCode會(huì)彈出推薦配置

image.png

選擇Perform Changes
xcode會(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!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容