程序员

CocoaPods使用总结

2018-04-28  本文已影响17人  jameiShi

CocoaPods 公共库的创建
CocoaPods 本地私有库的创建(模板创建方式)
CocoaPods 本地私有库的使用
CocoaPods 远程私有库的创建
CocoaPods 远程私有库的升级
CocoaPods 远程私有库的使用

CocoaPods 公共库的创建

~

CocoaPods 本地私有库的创建(模板创建方式)

1.创建一个 localLib 的文件夹,通过终端打开该文件夹

$ cd 路径

2.使用模板方式创建私有库
1.创建库

pod lib create MyLib0

进入选项设置:

略...

2.当看到下图命令提示,则创建成功

Ace! you're ready to go!
 We will start you off by opening your project in Xcode
  open 'MyLib0/Example/MyLib0.xcworkspace'

3.将核心代码拖入到Classes文件夹下面
4.打开 MyLib0.podspec文件,改homepage,source,description,summary 等文件.

  s.summary          = 'MyLib0.'
  s.description      = <<-DESC
mylib0………….
                       DESC
  s.homepage         = 'https://github.com/shijianmei'
  s.source           = { :git => '', :tag => s.version.to_s }

5.进入到 podspec 所在路径下,验证spec 有效性

pod lib lint

显示 MyLib0 passed validation. 则验证通过

cocoapods 本地私有库的引用

文件路径如下(MyLib0表示已经创建好的私有库,MyLib0Demo表示项目工程):

- MyLib0
  - MyLib0.podspec
  - MyLib0
  - LICENSE
  - Example
- MyLib0Demo
  - MyLib0Demo
  - MyLib0Demo.xcodeproj
  - MyLib0DemoTests
  - MyLib0DemoUITests

1.通过终端打开MyLib0Demo目录并初始化 pod:

pod init

2.打开 podfile 文件,添加 对MyLib0的依赖

 pod 'MyLib0', :path => '../MyLib0’

3.安装依赖库

pod install

CocoaPods 远程私有库的创建

要创建的私有库名:remotePrivateLib;在本地索引库的spec文件为privateSpec0.
1.创建一个私有的 Spec Repo,在~/.cocoapods/repos/下可以找到.

 pod repo add privateSpec0 https://github.com/shijianmei/RemotePrivateSpecs.git

2.打开一个准备好的目录,通过模板方式创建 remotePrivateLib,

pod lib create remotePrivateLib
  s.summary          = 'remotePrivateLib.'
  s.description      = <<-DESC
remotePrivateLib++++++++des
                       DESC
  s.homepage         = 'https://github.com/shijianmei/RemotePrivateLib'
  s.source           = { :git => 'https://github.com/shijianmei/RemotePrivateLib.git', :tag => s.version.to_s }

3.添加标签,并提交到远程 git 库上(这里用 github).

git tag '0.1.0'
git push --tags
//提交到 远程 git 库上
git add .
git commit -m 'lib文件 初始化'
git remote add origin https://github.com/shijianmei/RemotePrivateLib.git
git pull --rebase orgin master
git push -u origin master

4.进入到 podspec 所在路径下,验证spec 有效性

pod lib lint  //验证本地代码的有效性
pod spec lint//验证远程 spec 的有效性

5.上传 spec 文件到远程索引库(在 remotePrivateLib.podspec文件 目录下)

pod  repo push  remotePrivateSpec remotePrivateLib.podspec

CocoaPods 远程私有库的升级

1.首先把要升级的源代码拖到Classes文件夹里面
2.进入到测试工程pod install安装好测试代码
3.将. spec 文件里面的版本号进行
s.version = '0.2.0'
4.将本地私有库所有文件提交到远程私有库中, 并根据. spec 文件的版本号,打上对应 tag 值

git add .
git commit -m '升级了 lib'
git push origin master
git tag '0.2.0'
git push --tags

5.验证库的有效性(本地验证,远程验证):

pod lib lint  //验证本地代码的有效性
pod spec lint//验证远程 spec 的有效性

6.将 spec 文件提交到本地的私有索引库中,本地私有索引库会自动同步到远程私有库中.(在 remotePrivateLib.podspec文件 目录下)

pod  repo push  remotePrivateSpec remotePrivateLib.podspec

注意:上面的第5,6步也可以替换为下面步骤:
打开~.cocoapods/repos,手动创建一个匹配. spec 文件里版本号的新版本podspec.

CocoaPods 远程私有库的使用

1.通过xcode 创建一个项目remotePrivateLibDemo,通过终端打开其根目录,进行 pod 初始化:

pod init 

2.打开 podfile 文件,添加 对remotePrivateLib的依赖()

source 'https://github.com/shijianmei/RemotePrivateSpecs.git'
source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '9.0'
target 'remotePrivateLibDemo' do
  # use_frameworks!
  # Pods for remotePrivateLibDemo
    pod ‘remotePrivateLib’
  target 'remotePrivateLibDemoTests' do
    inherit! :search_paths
    # Pods for testing
  end
  target 'remotePrivateLibDemoUITests' do
    inherit! :search_paths
    # Pods for testing
  end
end
上一篇 下一篇

猜你喜欢

热点阅读