iOS开发 -多Target项目如何优雅的使用pods

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/CodingFire/article/details/84667207

多target项目适合需要经常打不通环境包的人,方便管理不同环境的项目,具体做法可以查看一个工程多环境切换,适合需要经常打很多不同环境包的人

多target的时候,如何使用pod呢?正常情况,你的pod是这样的:

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '8.0'
inhibit_all_warnings!

target 'TestDemo' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!
  # Pods for TestDemo
    pod 'UMessage'
    pod 'MJRefresh'
end

target 'TestDemoBeta' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for TestDemoBeta
    pod 'UMessage'
    pod 'MJRefresh'
end

target 'TestDemoTest' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for TestDemoTest
    pod 'UMessage'
    pod 'MJRefresh'
end

target TestDemoPlatform' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for TestDemoPlatform
    pod 'UMessage'
    pod 'MJRefresh'
end

如果使用的第三方比较少,你且可以这么写,但是如果比较多怎么办?这里博主给出一个优雅的写法:

# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '8.0'
inhibit_all_warnings!

def testDemo_pods
    pod 'UMessage'
    pod 'MJRefresh'
end
target 'TestDemo' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!
  # Pods for TestDemo
testDemo_pods
end

target 'TestDemoBeta' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for TestDemoBeta
testDemo_pods
end

target 'TestDemoTest' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for TestDemoTest
testDemo_pods
end

target TestDemoPlatform' do
  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks
  # use_frameworks!

  # Pods for TestDemoPlatform
testDemo_pods
end

也就是只需要增加一个定义:

//这里注意,testDemo_pods这个定义的名字一定不能大写字母开头,否则pod install不执行,小写即可
def testDemo_pods
end

你学会了么?喜欢就点个赞吧。

猜你喜欢

转载自blog.csdn.net/CodingFire/article/details/84667207
今日推荐