2017-08-14 116 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項目進行任何更改,並且它們不會丟失。