首先将自己需要上传的项目打包在一起
例如项目结构如下:
Pod::Spec.new do |s|
#别人pod下载时的名称,如:pod 'My_Test', '~> 2.0'
s.name = "My_Test"
#版本号
s.version = "2.0"
#授权条款(GitHub创建仓库时可以选择自动创建)
s.license = { :type => "MIT", :file => "LICENSE" }
#支持的最低系统版本号
s.platform = :ios, "8.0"
#简介
s.summary = "My_Test"
#项目Git主页
s.homepage = "项目地址"
#作者
s.authors = { "xiao can" => "邮箱" }
#Git下载地址
s.source = { :git => "项目git下载地址, :tag => "#{s.version}" }
#是否使用arc
s.requires_arc = true
# .h、.m文件
s.source_files = "My_Test/*.{h,m}"
#静态库文件
s.vendored_libraries = "My_Test/*.a"
#头文件
s.public_header_files = "My_Test/*.h"
#资源文件
s.resources = "My_Test/*.{bundle,plist,xcdatamodeld,json}"
#依赖的系统framework文件
s.frameworks = "UIKit","Foundation","Security"
#依赖的系统静态资源
s.libraries = "xml2","z"
#依赖的第三方库
s.dependency "SDWebImage"
end
然后cd到podspec文件所在目录
添加tag:
#查看本地tag
git tag
#添加tag
git tag 2.0
#将本地tag push到远程Git仓库
git push origin --tags
删除tag操作
#tag 删除
git tag -d 2.0
#远程服务器删除tag
# Git版本 > V1.7.0
git push origin --delete 2.0
#- 旧版本Git
git push origin :refs/tags/2.0
验证文件能否上传
pod lib lint
如果提示需要更新到最新版本pod,则需要执行更新pod命令
[!] Found podspec
test.podspec
Updating spec repomaster
CocoaPods 1.7.2 is available.
To update use:sudo gem install cocoapods
For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.7.2
//执行更新pod命令
sudo gem install cocoapods
如果遇到错误提示:ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/bin directory.
执行:
sudo gem install cocoapods -n /usr/local/bin
验证通过↓
上传到cocoapods
pod trunk push
或者
pod trunk push --allow-warnings
上传成功后会显示类似下面的信息
🎉 Congrats
🚀 My_Test (2.0) successfully published
📅 June 27th, 04:52
🌎 https://cocoapods.org/pods/My_Test
👍 Tell your friends!
接下来就可以在项目中使用你上传的文件了
pod 'My_Test', '~> 2.0'