2017-08-14 81 views
1

有没有一种方法可以在cocoapods pod中添加版本设置,而无需直接更改Pods项目或其他自动生成的东西,所以在pod install之后它仍然存在?具体而言,我需要在Mixpanel窗格中设置DISABLE_MIXPANEL_AB_DESIGNER=1以避免崩溃。Cocoapods pod稳定版本设置

,我发现了一些here,但它已经过时,因为(据我所知)podspec文件由吊舱所有者,而不是用户创建&看起来很奇怪。

+0

可以在这里使用'post_install'钩子吗? https://guides.cocoapods.org/syntax/podfile.html#post_install – Hodson

+0

@Hodson的确,它可以:)我已经根据您的评论发布了一个答案。 – nrx

回答

0

谢谢,@霍德森,这是解决方案。略有documentation修改的例子中,我们得到

post_install do |installer| 

    #Specify what and where has to be added 
    targetName = 'Mixpanel' 
    settingKey = 'DISABLE_MIXPANEL_AB_DESIGNER' 
    settingValue = 1 

    #Find the pod which should be affected 
    targets = installer.pods_project.targets.select { |target| target.name == targetName } 
    target = targets[0] 

    #Do the job 
    target.build_configurations.each do |config| 
     config.build_settings[settingKey] = settingValue 
    end 
end 

就在这个代码添加到您的podfile。显然,用同样的方法你可以对自动生成的pod项目进行任何更改,并且它们不会丢失。