所谓熟能生巧,这句话确实是有一定道理存在的。。不然何以见得,
今天来说一下,怎么让自己的代码保存到cocoapods,
第一步:创建github项目
1)登陆github (https://github.com)
2)创建你的github 项目,如下图填写号相关信息就可以了

第二步:将github远端项目拉取到本地
1)这里拉去到本地,你可以用github命令或者客户端都可以;
2)我这里采用SourceTree 获取项目到本地。

第三步:将需要托管的代码提交到github上
1)把你要提交的工程文件放到你要提交的目录下面,并根据情况建立你需要的分支(或者标签),并且用0.0.0的格式命名。保证你在创建 podspec 文件的时候可用。

2)将分子(或者tag)推送到远端
第四步:创建注册登陆cocoapods
1)注册:pod trunk register 邮箱地址 ‘用户名’ --description='描述信息'
/// 在终端输入
$ pod trunk register xxxxx.163.com 'xxxx'
/// 执行成功后会提示
[!] Please verify the session by clicking the link in the verification email that has been sent to 18381671632@163.com
然后打开邮箱验证即可,
2)验证是否注册成功 pod trunk me
如果成功了后会给出用户相关的信息
第五步:创建.podspec文件 (eg: xxx.podspec,其中xxx是你需要为你的库命的名字)
1)先cd 到你本地目录下面; ($ cd /Users/sobeycloud/Desktop/myGithubTest )
2)创建 xxx.podspec 文件;($ pod spec create xxxFramework )
创建好了会提示 Specification created at xxxFramework.podspec

第六步:编辑 xxx.podspec 文件,这里直接用文本编辑器打开,或者Sublime;我觉得这里时最麻烦的,这个文件只要稍微有一点错误就没法验证成功。所以要注意一下。。。
1)这里直接用文本编辑器打开;
#名字
s.name = "xxxFramework"
#版本号
s.version = "0.0.3"
#简介
s.summary = "A short description of xxxFramework."
#描述
s.description = "a repository demo"
#项目主页,不是git地址
s.homepage = "https://github.com/lovt/xxxFramework"
#存储库的git地址,以及tag值 (这个一定要和git 上的版本号(或者tag号)一致),不然无法找到路径。
s.source = { :git => "https://github.com/lovt/xxxFramework.git", :tag => "0.0.3" }
#开源协议
s.license = { :type => "MIT", :file => "LICENSE" }
#作者
s.author = { "lovt" => "18381671632@163.com" }
#支持的平台和版本号
s.platform = :ios, "8.0"
#是否支持ARC
# s.requires_arc = true
#系统所以来的框架
s.frameworks = 'UIKit', 'CoreFoundation'
#所依赖的第三方库,没有就不用写
# s.dependency "Masonry", "~> 1.0.0"
#需要托管的源代码路径
s.source_files = "Framework/TestObject.h","Framework/TestObject.m"
# 或者
s.source_files = "Framework/TestObject.{h,m}"
# 需要忽略的文件
# s.exclude_files = "Framework/TestObject.{h,m}"
# 框架体的子层目录关系
## 比如,框架下面有一个叫 Category 的目录信息相关数据。
s.subspec "Category" do |ss|
ss.source_files = 'ZHCustomKit/Category/*.{h,m}'
ss.frameworks = 'UIKit'
end
# 这个可以让你在使用cocoapods 的时候使用
# pod 'xxxFramework/Category'
# 的方式导入
# 这里一定要仔细注意每一个细节,这样才能保证在验证的时候可以通过。不然验证的时候不通过,查找很难受。。。(虽然有提示)我就是第一次的时候遇到很多的坑,(主要是不熟悉)。。
第七步:验证xxx.podspec 文件是否有效
1) ( pod spec lint --allow-warnings )忽略所有警告
2)如果验证不通过,那么按照提示修改 xxx.podspec 文件,继续验证,直到没有错误为止。
第七步:发布到cocoapods
1)验证成功后,你就可以发布了,
( pod trunk push --allow-warnings )
到此,你github 上面的代码,就可以用cocoapods 来管理了,
赶快去 pod search xxx 一下,看看有没有你的库吧。
这个应该是搜索不到的,因为你本地的文件还没有更新。
1)你可以用 pod search xxx --simple
2)你可以删除本地 search_index.json 文件后,在此收缩就可以了( rm search_index.json )就可以了。
3)或者你直接到cocoapods 去搜索吧。( https://cocoapods.org )
忽然感觉也就那么回事。。。
网友评论