大致流程
上传代码到github
创建podspec文件 ---验证
代码创建一个release版本
注册cocoapods账号(已有跳过)
代码上传至cocoapods
pod代码验证
登录https://github.com/
并创建项目

注意红框那的选择
创建完后就是用git拉取到本地,我使用的是sourcetree,这个不限制,开心就好。
然后放入一个功能代码(也可以放入一个演示的demo),因为我这里就一个验证手机号的方法,所以不添加什么例子demo。

推送到github上

创建podspec
cd到刚才的项目目录,然后使用命令
pod spec create cyhCheckphoneNum
cyhCheckphoneNum就相当于平时pod的AFNetworking中的
pod 'AFNetworking'
然后使用Xcode打开podspec,做一下修改
Pod::Spec.new do |spec|
spec.name = "cyhCheckphoneNum"
spec.version = "1.0.0"
spec.summary = "iOS to use for checkphoneNum"
spec.homepage = "https://github.com/CYHAI9/CyhpodDemo"
spec.license = "MIT"
spec.author = { "chenyinhai" => "cyhaie@163.com" }
spec.source = { :git => "https://github.com/CYHAI9/CyhpodDemo.git", :tag => "#{s.version}" }
# spec.platform = :ios
spec.platform = :ios, "9.0"
spec.source_files = "checkphoneNum/*.{h,m}"
#spec.exclude_files = "Classes/Exclude"
#spec.description = <<-DESC
# DESC
name:类库的名称这里字段介绍如下:
version:库的版本
summary:就是介绍语,就是下图这里

这里说一下
description
:这个是依赖于某个库,比如你要依赖CTMediator(一个中间件),那么就添加如下:
spec.description "CTMediator"
homtepage:Github上项目地址
license:许可证
author:作者
source:项目的https链接地址
source_files:要共享的代码,这里是cyhCheckphoneNum下面的所有代码
修改完后保存,验证
pod lib lint cyhCheckphoneNum.podspec
注意,如果复制粘贴命令没执行,请手动敲。
如果出现下面的说明对了

如果发现了多个警告,只要不是错误就行,警告可以直接忽略:
pod lib lint cyhCheckphoneNum.podspec --allow-warnings
在官网,也给出了详细的例子,比如如何里面添加其他依赖库,可以参考观摩
https://guides.cocoapods.org/making/specs-and-specs-repo.html
返回github项目,创建一个release版本1.0.0
选择release菜单
点击 Create a new release

点击Publish release即可

注册cocoapods账号,可以前往cocoapods官网
https://cocoapods.org/
执行命令行:
pod trunk register 邮箱地址 ‘用户名’ --description='描述信息'

之后会有一个邮箱验证,你可以打开你的邮箱验证即可。或者把链接放到浏览器验证。

pod trunk me

验证注册结果
再次验证podspec,没问题就可上传到cocoapods
pod spec lint
有警告就加上--allow-warnings忽略。
pod trunk push cyhCheckphoneNum.podspec

更新版本操作
首先修改podspec版本号,如果有其他信息要修改,也相应修改,然后验证是否能通过
上传更新github代码和podspec
同样创建新的release版本
最后
pod spec lint
pod trunk push cyhCheckphoneNum.podspec
有警告加入--allow-warnings 。
新建工程,pod入自己的组件
先使用
pod search cyhCheckphoneNum
查看能否找到

搜索不到请看后面的处理方式。
接下来是pod进工程,新建工程,cd到目录下
pod init
打开Podfile添加
pod 'cyhCheckphoneNum'
pod install

引入头文件
#import <cyhCheckphoneNum/NSString+checkNum.h>

Others
关于搜索不到的原因
执行pod setup
其实在你安装CocoaPods执行pod install时,系统会默认操作pod setup,然而由于中国强大的墙可能会pod setup不成功。这时就需要手动执行pod setup指令
pod setup
如果pod search操作还是搜索失败
删除~/Library/Caches/CocoaPods目录下的search_index.json文件
pod setup成功后,依然不能pod search,是因为之前你执行pod search生成了search_index.json,此时需要删掉。
终端输入:
rm ~/Library/Caches/CocoaPods/search_index.json
删除成功后,
再执行pod search
网友评论