在post_install中获取cocoapods版本

时间:2018-06-19 10:16:07

标签: ios cocoapods

是否可以在Podfile的post_install中知道安装了哪个版本的cocoapod?如果cocoapods版本为1.5

,我想添加两个配置设置
post_install do |installer|

    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
            if target.name === 'AlamofireImage'
                config.build_settings['SWIFT_VERSION'] = '3.3'
            end
            config.build_settings['CONFIGURATION_BUILD_DIR'] = '$PODS_CONFIGURATION_BUILD_DIR'

            # if cocoapods version == 1.5
            config.build_settings.delete('CODE_SIGNING_ALLOWED')
            config.build_settings.delete('CODE_SIGNING_REQUIRED')
        end
    end
end

1 个答案:

答案 0 :(得分:0)

我找到了一种方法,也许这不是最好的解决方案,但它可行:

pod_version = `pod --version` # using backticks you can execute shell commands and get result

pod_version ["\n"] = "" # here remove the trailing \n

if pod_version === '1.5.0'
    installer.pods_project.build_configurations.each do |config|
        config.build_settings.delete('CODE_SIGNING_ALLOWED')
        config.build_settings.delete('CODE_SIGNING_REQUIRED')
    end
end