Cocoapods相关指令合集(打pod库、.podspec文件中、Podfile文件中)

一、组件化开发打pod库以及.podspec文件中相关指令:

  1、 添加'本地的私有仓库'(Spec Repo)文件:

pod repo add baseSpecs http://***/***/specs.git

  2、查看本地的所有repo:

pod repo list

  3、打开本地配置仓库管理文件夹进行查看:

open ~/.cocoapods/repos

  4、创建一个pod库的标准模板:

pod lib create UIPoolSingleImage

  5、校验.podspec文件:

   注意:--allow-warnings :表示忽略警告。 --verbose:表示会输出详细的debug信息。

 本地校验:pod lib lint UIPoolSingleImage.podspec --allow-warnings
 线上校验:pod spec lint UIPoolSingleImage.podspec --allow-warnings

   注意:如果你制作的pod库,会依赖spec repository(配置文件仓库)中其他的私有仓库,则需要加上 --use-libraries。并且将 spec repository 的源加上,如下:

pod spec lint  UIPoolSingleImage.podspec --sources='http://***/***/specs.git','https://github.com/CocoaPods/Specs.git' --use-libraries

  6、将.podspec配置文件push到远端专门存储配置文件的仓库中:

pod repo push baseSpecs UIPoolSingleImage.podspec --allow-warnings --use-libraries --verbose

  7、将pod打成多个子pod,这样引用的时候,可以单独引用pod的某个子pod,在.podspec文件中这样设置:

s.default_subspec = 'All'
  s.dependency 'UIPoolHelper'
  
  s.subspec 'All' do |ss|
      ss.dependency 'UIPoolSingleImage/UIModel'
      ss.dependency 'UIPoolSingleImage/UICell'
      ss.dependency 'UIPoolSingleImage/Model'
  end
  
  s.subspec 'UIModel' do |sp|
      sp.source_files = 'UIPoolSingleImage/Classes/UIModel/*'
      sp.dependency 'UIPoolSingleImage/UICell'
      sp.dependency 'UIPoolBaseComponent/UIPoolImageView'
      sp.dependency 'UIPoolSingleImage/Model'
      sp.dependency 'UIModelGroup'
  end
  
  s.subspec 'Model' do |sp|
      sp.source_files = 'UIPoolSingleImage/Classes/Model/*'
      sp.dependency 'UIModelGroup'
  end
  
  s.subspec 'UICell' do |sp|
      sp.source_files = 'UIPoolSingleImage/Classes/UICell/*'
      sp.dependency 'UIPoolBaseComponent/UIPoolImageView'
      sp.dependency 'UIModelGroup'
  end

二、Podfile文件中相关指令:

  1、如果想单独在Debug环境或者Release环境安装某个pod库,可以使用下面的指令(如只在Debug环境安装):

pod 'Reveal-SDK',:configurations => ['Debug']

  2、安装pod的某个子pod:

1、pod 'UIPoolImageView/UIModel'

2、pod 'UIPoolImageView', :subspecs => ['UIModel', 'UICell']

  3、如果你想用一个自己开发的本地的Pod,你可以用path选项。使用这个选项后,Cocoapods会将给定的文件夹认为是Pod的源,并且在工程中直接引用这些文件:

pod 'AFNetworking', :path => '~/Documents/AFNetworking'

  4、屏蔽cocoapods库里面的所有警告:

inhibit_all_warnings!

   如果你想屏蔽某个单独的pod里面的警告也是可以的:

pod 'UIPoolImageView', :inhibit_warnings => true

  5、如果项目中添加了自己团队的私有库,需要将specs源添加到Podfile文件中(添加源),如下:

source 'https://github.com/CocoaPods/Specs.git'
source 'http://***/***/specs.git'

  6、如果项目中有多个target,而不同target之间并不全包含所有的pod,那么可以通过def命令来声明一个pod集:

def private_util

 pod 'UIPoolImageView','0.1.6'

end

  然后,在我们需要引入的target处引入,这样就可以解决不同target引用不同的pod组了:

target 'MyTarget' do

private_util

end

  7、如果我们想更改一些工程的配置参数,也可以在Podfile文件中完成,如下:

post_install do |installer|
  installer.pods_project.targets.each do |target|
   
    target.build_configurations.each do |config|
      if (config.name == 'AppStoreDebug' || config.name == 'Debug')
        config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = ['DEBUG=1']

        end
      end
    end

三、pod install、pod update、pod outdated 用法

   1、pod update --no-repo-update  :不更新repo,速度快

   2、pod update PodName --no-repo-update  :不更新repo,只更新某个库

   3、pod outdated  :查看哪些库有更新

   4、pod repo update  :单独更新本地repo

另一篇总结的:podfile语法

Cocoapods原理:CocoaPods 都做了什么?

pod install和pod update区别

发布了89 篇原创文章 · 获赞 92 · 访问量 30万+

猜你喜欢

转载自blog.csdn.net/u013602835/article/details/97130389