1.创建Specs的git路径
可以理解为库的头文件集合,该git里面储存了组件的.podspec文件
1.github创建空路径
示例地址为: ++https://github.com/Avanlanching/Specs.git++
2.将Specs 克隆到本地.cocoapod/repo/目录下
注意:/User/用户名/.cocoapods目录隐藏目录,需要"shift+command+."来显示;
可能存在访问权限的问题,需要先获取访问权限:
# 这里路径是.cocoapod里面
$sudo chmod -R 777 ../.cocoapods
1.SourceTree可视化界面克隆
2.终端指令
$pod repo add [name] [url]
e.g $pod repo add Specs https://github.com/Avanlanching/Specs.git
2.1 查看是否添加成功
$pod repo list
2.创建组件仓库(用于存放组件代码的仓库)
1.创建一个存放仓库的git路径
实例地址为:https://github.com/Avanlanching/cocoapodAvaDemo.git
2.创建组件
$pod lib create [组件名]
e.g pod lib create cocoapodAvaDemo
根据需求选择配置
iOS, ObjC, Yes, None, Yes/No, AA
3.代码编写
1.工程目录
2.文件目录
3.代码编写
注意:编码完成测试通过了,需要将书写的代码移动到Classes目录下面
3.1编写代码:
**注意:这里需要对事例工程中的Podfile进行pod install操作才会出现在Pod列表里面 **
3.2上传到git
A.指令上传
# 初始化git上传
$git init
$git add .
$git commit -m "init project"
$git remote add origin https://github.com/liuzhao/LZDemo.git
# 新增tag
$git tag '0.1.0' # 与.podspec文件中的s.version一致
$git push tags
B.SourceTree可视化上传
新增tag
3.创建组件.podspec文件管理
1. .podspec基本格式
#
# Be sure to run `pod lib lint cocoapodAvaDemo.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
#
Pod::Spec.new do |s|
s.name = 'cocoapodAvaDemo'
s.version = '0.1.0'
s.summary = 'A short description of cocoapodAvaDemo.'
# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!
s.description = <<-DESC
TODO: Add long description of the pod here.
DESC
s.homepage = 'https://github.com/avanlanching/cocoapodAvaDemo'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'avanlanching' => '18269285634@163.com' }
s.source = { :git => 'https://github.com/avanlanching/cocoapodAvaDemo.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '8.0'
s.source_files = 'cocoapodAvaDemo/Classes/**/*'
# s.resource_bundles = {
# 'cocoapodAvaDemo' => ['cocoapodAvaDemo/Assets/*.png']
# }
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
end
注意,每次进行修改需要对其进行update操作
$pod update (更新他人使用这个,防止混淆,可以一直采用此指令)
或
$pod update --no-repo-update
1.1 验证.podspec的合法性
1.本地验证
$pod lib lint --allow-warnings
可能遇到一个错误,解决方案
- ERROR | [iOS] unknow: Encountered an nuknown error (Malformed version number string ) during validation.
[!] xxxxxx did not pass validation, due to 1 error.
You can use the '--no-clean' option to inspect any issue.
注意这里可能是配置问题,解决方案如下:
$sudo gem install -n /usr/local/bin cocoapods
2.网络验证并推送到Spec远端
$pod repo push Spec --allow-warnings
e.g:$pod repo push Spec AvaDemo.podspec --verbose --allow-warnings
2.添加依赖
组件中依赖其他组件,不提倡在实例工程中的Podfile去添加依赖的SDK
提倡的操作,以AF为例子
在.podspec文件中添加
s.dependency 'AFNetworking', '~> 2.3'
// 多个SDK
s.dependency 'SDWebImage'
// 不指定版本号,为最新版本,如果没有依赖第三方的SDK,需要把s.dependency字段删除或者注释
添加完成后需要update
#针对.podspec文件
$pod update
#重复上述本地验证和推送到Specs的操作
4.主工程内引入
1.在编辑Podfile文件
添加两个Source
source 'https://github.com/CocoaPods/Specs.git' //公有组件
# source 'git@github.com:Avanlanching/Spec.git' // 私有组件
source 'https://github.com/Avanlanching/Specs.git'
pod 'AvaDemo' //常规语法