最近写了个 Luban_iOS 版的图片压缩库,并添加了
CocoaPods
支持,记录一下制作流程
一. 注册trunk
-
安装或升级 CocoaPods
sudo gem install cocoa pods
-
填写注册 邮箱和 GitHub 用户名
pod trunk register 你的邮箱 '用户名(注意是 Github 用户名)' --verbose
-
之后点击邮箱链接进行验证
-
查看注册信息
pod trunk me
- Name: GuoZhiQiang
- Email: 1029549847@qq.com
- Since: July 21st, 04:29
- Pods:
- Luban_iOS
- Sessions:
- July 21st, 04:29 - November 28th, 21:26. IP: 180.166.205.78
二. 代码库
-
创建名称
pod spec create Luban_iOS
-
在你项目的根目录,新建 Luban_iOS.podspec
vi Luban_iOS.podspec
-
这个文件里有许多已经写好的文档,我们需要的就是修改里面的文档,变为我们自己的库文档
用文本编辑器打开新建的文件,修改里面的内容并保存:
Pod::Spec.new do |s|
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.name = "Luban_iOS"
s.version = "1.0.0"
s.summary = "An UIImage's category to compress data almost without distortion ,Thanks to Android LuBan library"
s.description = <<-DESC
An UIImage's category to compress data almost without distortion ,Thanks to Android LuBan library. Just pod in 2 files and no need for any setups
DESC
s.homepage = "https://github.com/GuoZhiQiang/Luban_iOS"
# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.license = { :type => "MIT", :file => "LICENSE" }
# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.author = { "cook" => "http://www.jianshu.com/p/eb786aefdlle" }
s.social_media_url = "http://weibo.com/2639447231/profile"
# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.platform = :ios, "8.0"
# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.source = { :git => "https://github.com/GuoZhiQiang/Luban_iOS.git", :tag => "1.0.0" }
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.source_files = "Luban_iOS_Extension_h/*.{h,m}"
# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.requires_arc = true
- 注意:
s.source_files
是你的库文件在 Github 上的文件路径,我的结构目录如下:
Github 文件目录
-
s.description
的排版格式是固定的,不要修改,否则报错
-
验证 .podspec
pod lib lint Luban_iOS.podspec
如果正确,会显示:-> Luban_iOS (1.0.0) Luban_iOS passed validation.
-
打tag, 版本需要一致
git tag 1.0.0 git push --tag
三. 推送给 CocoaPods
-
推送到 CocoaPods
pod trunk push Luban_iOS.podspec
推送成功会提示:Updating spec repo `master` CocoaPods 1.3.0.beta.3 is available. To update use: `sudo gem install cocoapods --pre` [!] This is a test version we'd love you to try. For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.3.0.beta.3 -------------------------------------------------------------------------------- 🎉 Congrats 🚀 Luban_iOS (1.0.0) successfully published 📅 July 23rd, 22:22 🌎 https://cocoapods.org/pods/Luban_iOS 👍 Tell your friends! --------------------------------------------------------------------------------
-
搜索看是否能搜到
pod search Luban_iOS
-
如果搜不到自己的代码库,那么:
pod setup
rm -rf ~/Library/Caches/CocoaPods
- 然后在其他项目的 Podfile 里面 加入自己的代码库,然后
pod install
,应该可以安装成功
5.如果过了一段时间后,打了新 tag
,在终端通过 pod trunk me
查看个人信息时,也许会报错:
Authentication token is invalid or unverified. Either verify it with the email that was sent or register a new session.
然后,再注册一下邮箱就可以了:
pod trunk register 你的邮箱
网友评论