公有仓库

cocoaPods 公有仓库的建立 (分享自己的源码)

查看 cocoapods Specs 索引目录

两种方式

1.终端:   cd ~/.cocoapods/repos/master  
     open .   
        . 代表当前目录
        .. 代表上级目录

2.finder: 显示隐藏文件
先在终端执行命令
defaults write com.apple.finder AppleShowAllFiles -boolean true
killall Finder


15270005307052.jpg

查看远程 Specs 仓库

你会发现master是一个git仓库
远程仓库的地址 git remote -v

```
    // 输入浏览器查看
    origin  https://github.com/CocoaPods/Specs.git (fetch)
    origin  https://github.com/CocoaPods/Specs.git (push)
    
```

继续查看文件目录 Specs

15270010438920.jpg

这个时候我们输入 pod search Defaultskit (通过json文件获取)


15270513422794.jpg

可以看到里面有源码的下载地址 source versions 有多少个版本 等配置信息

我们在用cocoaPods 发布源码时, 需要将仓库的描述信息push到远程仓库中, 使用pod命令即可实现

创建 cocoaPods 账户

要想通过cocoaPods 上传我们的仓库配置信息, 需要注册cocoaPods账号

1.在终端执行命令
pod trunk register github_email 'user_name' --verbose

github_email  你的github账号注册时用的邮箱地址  user_name 自定义

出现下面的这条信息时, 说明账号注册成功, 到邮箱点击链接, 进行验证
Please verify the session by clicking the link in the verification email that has been sent to you_email

2.验证成功如下图


15270541636638.jpg

3.确认注册信息后, 在终端执行
pod trunk me

可看到注册信息如下图


15270542412370.jpg

到此, 注册账号完成

创建git仓库 (用来存放源码)

下来我们在github上 创建一个放我们要共享代码的仓库
如无github账号,先注册github账号

15270551935742.jpg
15270553579723.jpg
15270554163107.jpg

点击第二步之后, 复制了git仓库的地址

接下来在终端执行

cd 到你想要存放代码的目录

将github上创建的项目clone到本地
git clone https://github.com/xuxueyong/TestDemo.git

在testDemo目录下创建

  • code 文件夹 用来存放我们的代码
  • LICENSE 文件许可证
  • READ.me 是创建仓库的时候就存在的 (仓库使用说明)
  • podspec文件 用来描述和配置仓库信息 (非常重要)

创建podspec文件

在终端执行
pod spec create code

出现 Specification created at code.podspec
表示 code.podspec 创建成功

查看该文件有什么内容 发现很多字段, 我这里有整理好的字段 (ruby脚本语言)


Pod::Spec.new do |s|
  s.name         = "code"         # 项目名称
  s.version      = "1.0.0"        # 版本号 与 你仓库的 标签号 对应
  s.license      = "MIT"          # 开源证书
  s.summary      = "A delightful TextField of PhoneNumber" # 项目简介

  s.homepage     = "https://github.com/xuxueyong" # 你的主页
  s.source       = { :git => "https://github.com/xuxueyong/TestDemo.git", :tag => "#{s.version}" }#你的仓库地址,不能用SSH地址
  s.source_files = "code/*.{h,m}" # 你代码的位置, code/*.{h,m} 表示 code 文件夹下所有的.h和.m文件
  s.requires_arc = true # 是否启用ARC
  s.platform     = :ios, "9.0" #平台及支持的最低版本
  s.frameworks   = "UIKit", "Foundation" #支持的框架
  # s.dependency   = "AFNetworking" # 依赖库
  
  # User
  s.author             = { "xueyong" => "794334810@qq.com" } # 作者信息
  s.social_media_url   = "https://github.com/xuxueyong" # 个人主页
end

验证 本地的.podspec 文件是否正确

15270578234504.jpg

异常情况 如果使用swift 语言的时候, 可能会出现

[!] BYPhoneNumTF did not pass validation, due to 1 warning (but you can use `--allow-warnings` to ignore it) and all results apply only to public specs, but you can use `--private` to ignore them if linting the specification for a private pod.
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run: 
    `echo "2.3" > .swift-version`.
You can use the `--no-clean` option to inspect any issue.

从异常信息可以看出, 我们需要使用 --allow-warnings 参数
pod lib lint --allow-warnings

给仓库打上标签

在打标签之前 先提交我们刚才创建的那些文件到远程仓库

git add .
git commit -m '测试公有库创建'
git push

// 初次提交代码, 是需要登录的
Username for 'https://github.com': 794334810@qq.com
Password for 'https://794334810@qq.com@github.com': 

给仓库打上标签 也就是之前看到的版本号

仓库版本号 要与.podspec 文件中的 s.version = '1.0.0' 相对应

// 打标签
 git tag -a '1.0.0' -m '仓库打标签'
     -a 表示添加标签  -m 表示 注释信息  comment 
     
// 推送到远程仓库
 git push origin --tags
 提示  * [new tag]         1.0.0 -> 1.0.0  说明推送成功

发布 .podspec文件

将code.podspec文件发布到公有spec上

在终端执行命令
pod trunk push code.podspec

提示错误信息
  You (794334810@qq.com) are not allowed to push new versions for this pod. The owners of this pod are 1069156011@qq.com.


  说明公有库的拥有者有错
 移除公有库的拥有者  pod trunk remove-owner code.pospec 1069156011@qq.com

发生了那些操作:

  • Updating spec repo master
  • 将 .podspec 文件转成 JSON 格式
  • 对 master 仓库 进行合并 ,再次提交master仓库

产生异常信息 {"name"=>["is already taken"]}

说明这个名字 已经被别人使用了

将名字改为 yongTestCocoaPodsShare

提交成功后
https://cocoapods.org/pods/yongTestCocoaPodsShare

15270620746178.jpg

说明发布成功 可以通过上面的URL查看

15270622224580.jpg

更新 pods

在终端执行 pod setup

pod search yongTestCocoaPodsShare
出现异常 Unable to find a pod with name, author, summary, or description matching yongTestCocoaPodsShare

估计是更新不及时

https://github.com/CocoaPods/Specs/commits/master

因为在这里可以看到提交记录

使用

新建立一个项目
在 Podfie 文件中使用 pod 'yongTestCocoaPodsShare', '1.0.2'
报异常信息 [!] CocoaPods could not find compatible versions for pod "yongTestCocoaPodsShare":
In Podfile:
yongTestCocoaPodsShare (= 1.0.2)

Specs satisfying the yongTestCocoaPodsShare (= 1.0.2) dependency were found, but they required a higher minimum deployment target.

解决方法
pod setup
如果还是异常
执行 删除缓存操作 rm -fr ~/.cocoapods/repos/master
再次执行 pod setup

更新维护

  • 修改 代码
  • 修改 .podspec 文件
  • 打标签
  • 推送到 pods 远程库
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容