ios自制framework上传到cocoapods

2,033 阅读2分钟

上一篇:iOS自制framework总结 

Framework制作完成之后,讲一下如何上传到cocoapods让大家使用。

 1,创建仓库 

在GitHub上创建自己的仓库,填写相关的信息,选择相应的配置,点击创建仓库按钮之后就生成了一个仓库。如果你选择的有License的话,此时仓库中就存在默认的README和License两个文件。

2,克隆仓库到本地,打开终端,输入如下命令: 

 命令:git clone   #克隆仓库到本地,如directory参数为空则克隆到当前目录
exm:git clone https://github.com/dxsGitHub/ListEmptyDataStyle.git 

 3,创建podspec文件及其配置 

1.运行如下命令,在文件夹会生成一个ListEmptyDataStyle.podspec文件

pod spec create ListEmptyDataStyle

2.用Xcode打开之后会有许多默认配置,定制之后大致是下面这个样子

Pod::Spec.new do |spec|

  spec.name         = "ListEmptyDataStyle"
  spec.version      = "1.0.3"
  spec.summary      = "ListEmptyDataStyle 设置UITableView、UICollectionView无数据时候的占位视图样式."
  spec.homepage     = 'https://github.com/dxsGitHub/ListEmptyDataStyle'
  spec.license      = { :type => "MIT", :file => "LICENSE" }
  spec.author             = { "dxs" => "dxs_high@icloud.com" }
  spec.platform     = :ios, "13.0"
  spec.ios.deployment_target = "13.0"
  spec.source       = { :git => 'git://github.com/dxsGitHub/ListEmptyDataStyle.git', :tag => "1.0.3" }
  
  #需要认真设置 - 对应你的文件所在路径
  spec.resources  = "ListEmptyStyle/*.{bundle}"
  spec.source_files  = "ListEmptyStyle/*.{h,m}"

  spec.requires_arc = true

end 

 4,本地仓库添加功能代码、资源文件,然后提交并推送到远端,命令如下:

 git add .                        #跟踪所有项目(会提交所有的文件和资源改动) 
git commit -m "message"          #提交信息 
git push                         #把本地修改推到远端 
git tag -a v1.0.0 -m "v1.0.0"    #打上标记Tag

 5,终端执行命令 + 验证信息 + 验证podspec文件 

1,执行命令注册trunk,然后会收到一封邮件,点击邮件中的链接进行激活

 pod trunk register EMAIL [YOUR_NAME] #注册 

2,执行命令查看信息

 pod trunk me 

3,执行命令验证podspec文件

pod lib lint ListEmptyDataStyle.podspec  --use-libraries  --allow-warnings --sources='https://github.com/CocoaPods/Specs.git' 

4,看到这个绿色提示说明验证通过了,如果提示有错,根据提示逐个改正。

 6,上传podspec文件到cocoapods

 pod trunk push --allow-warnings

7,pod setup 和 pod search确认

上传成功之后,执行 pod setup 和 pod search 查询自己的库,感觉一时半会的可能查不到,这个很正常,你可以在Demo里写个podfile试一下!

8,爬坑总结 

第六步无敌大坑:必须先要在GitHub你的仓库发布和podspec版本对应的Release版本,如果不发Release版本的话,会各种找不到!