p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC" }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
p.p1 { margin: 0.0px 0.0px 10.0px 0.0px; line-height: 17.0px; font: 14.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
li.li2 { margin: 0.0px 0.0px 14.0px 0.0px; line-height: 17.0px; font: 14.0px "Yuanti SC"; color: #000000 }
li.li3 { margin: 0.0px 0.0px 14.0px 0.0px; line-height: 17.0px; font: 14.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
span.s2 { background-color: #ffffff }
span.s3 { background-color: #ffffff }
ol.ol1 { list-style-type: decimal }
创建一个私有的podspec包括如下那么几个步骤:
- 创建并设置一个私有的Spec Repo。
- 创建Pod的所需要的项目工程文件,并且有可访问的项目版本控制地址。
- 创建Pod所对应的podspec文件。
- 本地测试配置好的podspec文件是否可用。
- 向私有的Spec Repo中提交podspec。
- 在个人项目中的Podfile中增加刚刚制作的好的Pod并使用。
- 更新维护podspec。
本地私有仓库:
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; line-height: 17.0px; font: 14.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
什么是Spec Repo?他是所有的Pods的一个索引,就是一个容器,所有公开的Pods都在这个里面,他实际是一个Git仓库,remote端在GitHub上,当我们使用Cocoapods后它会被clone到本地的~/.cocoapods/repos目录下,可以进入到这个目录看到master文件夹就是这个官方的Spec Repo了。这个master目录的结构是这个样子的。
1.在码云上创建一个私有库:
https://gitee.com/Steven_Hu/HKCommonTools.git
2.将私有库添加到本地
pod repo add REPO_NAME SOURCE_URL
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC"; color: #000000 }
span.s1 { color: #000000 }
span.s2 { background-color: #ffffff }
$pod repo add CommomToolSpec https://gitee.com/Steven_Hu/HKCommonTools.git
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
Cloning spec repo `CommomToolSpec` from `https://gitee.com/Steven_Hu/HKCommonTools.git`
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
3.cd 到桌面开始组件化抽取
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
cd ./Desktop
pod lib create HKCommonTool
Cloning `https://github.com/CocoaPods/pod-template.git` into `HKCommonTool`. Configuring HKCommonTool template. ! Before you can create a new library we need to setup your git credentials. What is your email? > 916109796@qq.com ! Setting your email in git to 916109796@qq.com git config user.email "[email protected]" ------------------------------ To get you started we need to ask a few questions, this should only take a minute. If this is your first time we recommend running through with the guide: - https://guides.cocoapods.org/making/using-pod-lib-create.html ( hold cmd and double click links to open in a browser. ) What platform do you want to use?? [ iOS / macOS ] > iOS What language do you want to use?? [ Swift / ObjC ] > ObjC Would you like to include a demo application with your library? [ Yes / No ] > Yes Which testing frameworks will you use? [ Specta / Kiwi / None ] > None Would you like to do view based testing? [ Yes / No ] > Yes What is your class prefix? > HK Running pod install on your new library. Pod installation complete! There are 2 dependencies from the Podfile and 1 total pods installed.
把要抽取的工具类拖到 Pods ->Development Pods 下的Replace.m 中并替换掉它。
cd 到工程目录下 执行 pod install
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
4.推送到远程私有库(git远程仓库地址,或者码云等)
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
//关联远程仓库
在 HKCommonTool 工程目录下 执行:
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
$git remote add origin https://gitee.com/Steven_Hu/HKCommonTools.git
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
//提交到git仓库
git add . git commit -m ‘HKCommonTool初始化‘ git push origin master git push origin master -f //全局提交
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
5.修改 .podspec 文件并提交
Pod::Spec.new do |s| #名称 s.name = ‘HKCommonTool‘ #版本号 s.version = ‘0.1.0‘ #摘要 s.summary = ‘HKCommonTool 常用工具类归类‘ #描述 s.description = ‘iOS开发常用的常用宏定义和工具类,网络框架等~‘ #远程仓库首页链接 s.homepage = ‘https://gitee.com/Steven_Hu/HKCommonTools‘ #截图 # s.screenshots = ‘www.example.com/screenshots_1‘, ‘www.example.com/screenshots_2‘ #许可证 s.license = { :type => ‘MIT‘, :file => ‘LICENSE‘ } #作者 s.author = { ‘HJT916109796‘ => ‘[email protected]‘ } #source来源 s.source = { :git => ‘https://gitee.com/Steven_Hu/HKCommonTools.git‘, :tag => s.version.to_s } #社交链接 # s.social_media_url = ‘https://twitter.com/<TWITTER_USERNAME>‘ #开发版本 s.ios.deployment_target = ‘9.0‘ #资源文件路径 s.source_files = ‘HKCommonTool/Classes/**/*‘ #资源包 # s.resource_bundles = { # ‘HKCommonTool‘ => [‘HKCommonTool/Assets/*.png‘] # } # s.public_header_files = ‘Pod/Classes/**/*.h‘ # s.frameworks = ‘UIKit‘, ‘MapKit‘ # s.dependency ‘AFNetworking‘, ‘~> 2.3‘ end
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
校验文件的正确性:
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
$pod lib lint HKCommonTool.podspec
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
重新提交:
git add . git commit -m ‘修改podspec文件~‘ git push origin master
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
设置tag
git tag git tag ‘0.1.0‘ git push --tags
6.推送本地Spec到远程仓库
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC"; color: #0433ff; background-color: #ffffff }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC"; color: #ff2600; background-color: #ffffff }
span.s1 { }
git fetch origin master
git checkout master
git branch --set-upstream-to=origin/master master
Branch ‘master‘ set up to track remote branch ‘master‘ from ‘origin‘.
git pull
pod repo update
pod repo push CommomToolSpec HKCommonTool.podspec
git push
git pull
git push origin master
7.如何使用:
编辑Podfile文件如下:
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC"; color: #ff2600; background-color: #ffffff }
span.s1 { color: #000000 }
编辑Podfile 必须加 git => ‘https://gitee.com/Steven_Hu/HKCommonTools.git‘
platform :ios, ‘9.0‘ use_frameworks! target ‘HKTools‘ do pod ‘XCDemo‘ ,:git => ‘https://gitee.com/Steven_Hu/XCTool.git‘ pod ‘HKCommonTool‘ ,:git => ‘https://gitee.com/Steven_Hu/HKCommonTools.git‘ # pod ‘HKTools‘, :path => ‘./Lib/HKTools‘ # pod ‘HKTools‘, :podspec => ‘~/.cocoapods/repos/HKTools/HKTools.podspec‘ end
8.其他常用命令:
删除本地私有库:
$ pod repo remove hktools
Removing spec repo `gitee-steven_hu-hktools`
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { }
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC" }
p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; line-height: 18.0px; font: 14.0px "Yuanti SC"; color: #afad24; background-color: #ffffff }
p.p3 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px "Yuanti SC"; color: #000000; background-color: #ffffff }
span.s1 { color: #000000 }
span.s2 { }
原文地址:https://www.cnblogs.com/StevenHuSir/p/ComponentBased_PrivateRepo.html