cocoapods自定义库

本地私有库

1.编写需要封装的库源码


2.使用git管理源码:

git add .

git commit -m '描述信息'


3.创建spec文件:pod spec create 自定义名称


4.修改spec文件

到此:cocoapods本地私有库已经制作完成。


使用本地私有库:

1.创建一个项目


2.进入项目目录使用pod init命令生成一个Podfile文件


3.修改Podfile文件:导入本地私有库:

pod  'XPLocalPriLib', :path=>'本地私有库路径(如:../localPrivLib/XPLocalPriLib)'


4.在项目目录中输入pod install 安装本地私有库



远程共有库

1.编写源码库


2.在第三方平台(github,码云,码市等平台)创建源码远程库,记得公开


3.上传本地源码库到远程

git add .

git commit -m '描述信息'

git remote add origin 远程URI

git push -u origin master :第一提交是记得加-u,以后提交就不用了

git tag '0.0.1'

git push --tags


4.创建spec描述文件:pod spec create 名称


5.修改spec描述文件


6.最好手动验证一下spec文件:

pod lib lint:本地验证

pod spec lint 名称:远程验证(需要框架源码有tag,否则不通过)


7.注册trunk:pod trunk register 邮箱 "姓名"


8.在邮箱中收到一个路径,复制路径,在网页在打开,注册成功


9.通过trunk把我们的spec描述文件上传到cocoapods的spec(https://github.com/CocoaPods/Specs)中:pod trunk push


10.需要等一段时间,提交完成后,就可以使用 pod setup 跟新本地索引库


11.可以使用pod search 自己共有库的名称


使用共有索引库:

1.创建一个项目


2.进入项目目录使用pod init命令生成一个Podfile文件


3.修改Podfile文件:导入本地私有库:

pod  'XPRemoteLib', '~>0.0.1'


4.在项目目录中输入pod install 安装远程共有库




远程私有库:(工作中常用)

使用第三方框架创建Podfile文件:pod init

安装第三方框架:pod install 

查看第三方仓库:pod repo

移除第三方仓库:pod repo remove 名称

添加第三方仓库:pod repo add 名称 远程URI

清理第三方仓库:pod cache clear --all

初始化(下载第三方所有的框架信息到本地缓存库,同时更新索引库):pod setup

本地索引库路径: ~/Library/Caches/CocoaPods/

安装pod的路径最好在:/usr/local/bin

第三方pod框架索引路径:/Users/apple/.cocoapods/repos/master


1.在第三方平台新建远程索引库和远程框架源码库


2.创建本地私有Spec  repo:pod repo add XPRemotePriLib 远程URI


3.创建框架文件,编写源码,测试


4.框架源码测试没问题后提交到远程框架源码库中

git add .

git commit -m '描述信息'

git remote add origin 远程源码库的URI(用ssh)

git push -u origin master

git tag '0.0.1'/git tag -m '描述信息' '0.0.1'

git push --tag


5.创建spec文件:pod spec create 名称


6.修改没问题后,验证spec文件:

pod lib lint:本地验证

pod spec lint 名称:远程验证(需要框架源码有tag,否则不通过)

 

7.本地测试spec文件:

创建Podfile文件:pod init

修改Podfile文件:Pod 'XPCategory',:podspec=>'path/xxx.podspec'

执行pod install安装


8.测试完成可用后,提交到远程私有Spec库中:pod repo push XPRemotePriLib  XPRemotePriLib.podspec


9.不需要更新本地库了,因为是先从本地库提交出去的,别人要使用才需要更新本地库


10.测试在Podfile中使用时,需要说明来源,在Podfile最上面加上:

source 'git@git.coding.net:wangshunzi/XMGFMSpecs.git'

source 'https://github.com/CocoaPods/Specs.git'  #官方仓库的地址

引用框架的地方:pod 'XXXLib/XXXSub'


11.别人使用方法:

需要你分配权限给他

然后就和10一样了

pod install  安装

pod update --no-repo-update  如果上一次安装过了,别人把第三方框架改了,我们再次安装使用



拆分自定义框架:

只需要修改spec文件即可:

修改:s.source_files = 'XPCustomLib/Classes/**/*'

把这句注释掉,

使用以下方式代替:

s.subspec 'XPBase' do |b|

b.source_files = 'XPCustomLib/Classes/Base/**/*'

end

s.subspec 'XPCategory' do |c|

c.source_files = 'XPCustomLib/Classes/Category/**/*'

end

s.subspec 'XPViewFrame' do |v|

v.source_files = 'XPCustomLib/Classes/ViewFrame/**/*'

end

s.subspec 'XPNetwork' do |n|

n.source_files = 'XPCustomLib/Classes/Network/**/*'

n.dependency  'AFNetworking'   #这句话是说明我们这个字框架依赖afn框架

end



使用时候你看你需要的框架可能用不了那么多的话,你就只需要根据自己的需求引入:

如:我只需要自定义网络框架:

pod  'XPCustomLib/XPNetworking'


如果要导入多个:

pod  'XPCustomLib/XPNetworking'

pod  'XPCustomLib/XPViewFrame'


也可以简写:

pod 'XPCustomLib', :subspecs  =>  ['XPNetworking','XPViewFrame']





模版工程生产:

pod lib create XPTestCategory

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值