iOS开发过程中,我们常用到从CocoaPods安装的第三方库。本文教大家把自己制作的第三方库,上传到CocoaPods。
注册CocoaPods命令:
pod trunk register 你的邮箱 '你的用户名'
执行注册命令之后,会收到一封邮件,点一下邮件里面的验证链接即可继续在终端进行操作。
1、cd到你的项目根目录,创建podspec命令
pod spec create YYText-swift
命令成功之后会得到一个YYText-swift.podspec文件,如图
这里贴一下podspec的配置及说明,直接复制改成你的信息即可
Pod::Spec.new do |s|
s.name = "YYText-swift" # 项目名称
s.version = "1.0.2" # 标签号标签号标签号!重要的事情说三遍
s.swift_versions = "5.0"
s.summary = "致敬YYText的作者,YYText的Swift版本" # 项目简介
s.homepage = "https://github.com/laoou002/YYText-swift" # 你的主页
s.source = { :git => "https://github.com/laoou002/YYText-swift.git", :tag => "#{s.version}" }# 你的仓库git地址
s.source_files = 'YYText-swift/YYText/*.swift', 'YYText-swift/YYText/*/*.swift' # 此处有多少层级,写全,否则会编译失败
s.platform = :ios, "13.0" #平台及支持的最低版本
s.frameworks = "UIKit", "Foundation" #支持的框架
s.requires_arc = true # 是否使用arc
s.license = { :type => 'MIT', :file => 'LICENSE' } # 开源证书
# User
s.author = { "你的用户名" => "你的邮箱" } # 作者信息
end
标签号对不上的话,后续会上传失败,可标签号可去github搜索常用的第三方库参考,如图:
声明MIT也很简单,在你项目根目录新建一个名为LICENSE的文件,然后复制如下内容,把版权署名改为你自己的即可:
MIT License
Copyright (c) 2022 YongHeng.Ou
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2、验证命令
pod spec lint --allow-warnings
命令后面最好加上--allow-warnings, 否则有警告时会失败。第三方库常有一些可忽略的警告
如果你的代码和配置没有问题,验证通过会输出如下日志:
YYText-swift.podspec passed validation.
3、上传到cocoapods命令
pod trunk push YYText-swift.podspec --allow-warnings
成功的话,终端会输入如下
🎉 Congrats
🚀 YYText-swift (1.0.4) successfully published
📅 May 18th, 20:57
🌎 https://cocoapods.org/pods/YYText-swift
👍 Tell your friends!
上传成功之后,cocoapods有延迟,一般不会马上更新到官方,正常现象,不要害怕。