Cocoapods技术沙龙

本文介绍如何使用Cocoapods搭建iOS项目的私有库,包括安装配置、创建私有仓库、上传和管理私有库的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Cocoapods是iOS模块化解决方案的基础,通过创建私有仓库来快速实现app的模块化开发。
warnning!!!!!!!!!!
cocoaPods版本如果是1.0.1和1.1.0的beta版本是,会导致pod repo push 失败,所以建议大家将cocoaPods版本稳定在1.0.0或者1.1.0,请使用命令sudo gem install cocoapods
安装cocoapods
gem sources –remove https://rubygems.org/ 删除亚马逊源
gem sources -a https://ruby.taobao.org/ 转换为淘宝源
gem sources -l 检验ruby源成功与否
sudo gem install cocoapods 开始安装cocoapods
可能会遇到的问题查看此贴
cocoapods用法
便捷管理第三方库
通过podfile文件集中管理
pod install
pod update
pod search XXX
版本号控制example
pod ‘AFNetworking’ //不显式指定依赖库版本,表示每次都获取最新版本
pod ‘AFNetworking’, ‘2.0’ //只使用2.0版本
pod ‘AFNetworking’, ‘> 2.0’ //使用高于2.0的版本
pod ‘AFNetworking’, ‘>= 2.0’ //使用大于或等于2.0的版本
pod ‘AFNetworking’, ‘< 2.0’ //使用小于2.0的版本
pod ‘AFNetworking’, ‘<= 2.0’ //使用小于或等于2.0的版本
pod ‘AFNetworking’, ‘~> 0.1.2’ //使用大于等于0.1.2但小于0.2的版本
pod ‘AFNetworking’, ‘~>0.1’ //使用大于等于0.1但小于1.0的版本
pod ‘AFNetworking’, ‘~>0’ //高于0的版本,写这个限制和什么都不写是一个效果,都表示使用最新版本
cocoapods源
公有源 source ‘https://github.com/CocoaPods/Specs.git
私有源 source ‘http://git.51caocao.cn/junqi/caocaoRepo.git
创建私有源,注意repo源是存放podspec的仓库,不是存放代码的仓库,要注意区分
可以通过open ~/.cocoapods/repos这个命令查看本地私有源
gitlab创建一个仓库XXX url
pod repo add XXX //此命令是将私有仓库放入CocoaPods中进行管理,以后的私有仓库代码是先从这个里面的podspec查找,在进行更新
创建cocoapods私有库
基于私有源
创建一个新的例子工程 pod lib create XXX 或者本地自己新建podspec以及LICENSE
将gitignore文件中的#Pods/前面的#号去掉,不追踪Pods的变化,如果没有gitignore文件,自己新建一个gitignore
编写podspec文件
上传本地git到远端
git add . //将工程文件添加入git追踪
git commit -m “xxx” //将本地更改保存
git remote add origin http://git.51caocao.cn/ios-team/YXGeneral.git 将本地代码和远端关联
git push -u origin master 推送本地代码到远端仓库
打tag:对应podspec里面的tag版本号
git tag -a 2.0.0 -m “大改版done” //打tag,注意这个tag最好和podsepc保持一致
git push origin 2.0.0 推送tag标签到远端
上传spec文件到私有源仓库 pod repo push XXXRepo XXXX.podspec –use-libraries –verbose –allow-warnings //推送私有库的podspec文件到私有仓库,三个参数最好默认加上
–use-libraries 允许使用framework和library
–verbose 打印详细信息
–allow-warnings 允许警告
添加source源测试
source ‘http://git.51caocao.cn/luminary/TestSourceRepo.git’ //本地私有库
source ‘https://github.com/CocoaPods/Specs.git’ //cocoapods官方库
spec文件编写及校验
单独创建spec文件 pod spec create XXX
格式转json pod ipc spec Name.podspec >> Name.podspec.json
s.name:名称,pod search 搜索的关键词
s.version:版本
s.summary:简介,pod search 搜索的关键词
s.homepage:主页地址,例如Github地址
s.license:许可证
s.author:作者
s.social_media_url:社交网址
s.platform:平台
s.source:Git仓库地址,例如在Github地址后边加上 .git 就是Git仓库地址,常见写法如下
s.source_files:需要包含的源文件,常见的写法如下
s.resources:需要包含的图片等资源文件
s.dependency:依赖库,不能依赖未发布的库
s.dependency:依赖库,如有多个可以这样写
s.requires_arc:是否要求ARC
s.public_header_files = “Classes/*.h” 暴露的头文件
s.framework = “SomeFramework” 依赖的系统framework
s.library = “iconv” 依赖的系统静态库
s.vendored_frameworks 依赖的第三方framework
s.vendored_libraries 依赖的第三方静态库
s.dependency “JSONKit”, “~> 1.4” 依赖的第三方库
gitignore_global设置
具体操作是:打开一个Finder 同时按住commamd+shift+G,输入~/.gitignore_global,然后前往,打开文件,将下面的文字复制粘贴进去保存即可

OS X

.DS_Store

Xcode

build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/
*.xccheckout
profile
*.moved-aside
DerivedData
*.hmap
*.ipa

Bundler

.bundle
Carthage

We recommend against adding the Pods directory to your .gitignore. However

you should judge for yourself, the pros and cons are mentioned at:

http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control

Note: if you ignore the Pods directory, make sure to uncomment

pod install in .travis.yml

#

Pods/
关于xcworkSpace中Pods的申明
这里写图片描述

这里写图片描述

常用操作如下:
echo “2.3” > .swift-version

pod lib lint

git remote add origin https://github.com/郏国上/JGSOutDoorClub.git

pod repo push 51caocao-jiaguoshang-jgsoutdoorclub JGSOutDoorClub.podspec –use-libraries –verbose –allow-warnings

git status

pod lib lint /Users/jiaguoshang/Desktop/JGSOutDoorClub/JGSOutDoorClub/JGSOutDoorClub.podspec

pod repo push 仓库名字 ❎❎❎.podspec –use-libraries –verbose –allow-warnings

pod lib lint –no-clean –allow-warnings

pod repo push JGSRepo test.spec.podspec –use-libraries –verbose –allow-warnings

pod spec create test.spec

pod repo add JGSRepo http://git.51caocao.cn/jiaguoshang/TestJGs.git

pod repo add 51caocao-jiaguoshang-jgsoutdoorclubrepo http://git.51caocao.cn/jiaguoshang/TestJGs.git

pod repo push 51caocao-jiaguoshang-jgsoutdoorclubrepo JGSOutDoorClub.podspec –use-libraries –verbose –allow-warnings

JGSOutDoorClub.podspec文件代码示例
#

Be sure to run `pod lib lint JGSOutDoorClub.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 http://guides.cocoapods.org/syntax/podspec.html

#

Pod::Spec.new do |s|
s.name = ‘JGSOutDoorClub’
s.version = ‘0.1.0’
s.summary = ‘JGSOutDoorClub.’

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 = ‘http://www.baidu.com/
# s.screenshots = ‘www.example.com/screenshots_1’, ‘www.example.com/screenshots_2’
s.license = { :type => ‘MIT’, :file => ‘LICENSE’ }
s.author = { ‘郏国上’ => ‘jiaguoshang@geely.com’ }
s.source = { :git => ‘http://git.51caocao.cn/jiaguoshang/JGSOutDoorClub.git‘, :tag => s.version.to_s }
# s.social_media_url = ‘https://twitter.com/

s.ios.deployment_target = ‘8.0’

s.source_files = ‘JGSOutDoorClub/Classes/*/

# s.resource_bundles = {
# ‘JGSOutDoorClub’ => [‘JGSOutDoorClub/Assets/*.png’]
# }

# s.public_header_files = ‘Pod/Classes/*/.h’
s.frameworks = ‘UIKit’, ‘MapKit’, ‘Foundation’
# s.dependency ‘AFNetworking’, ‘~> 2.3’
end

把私有仓库上传成功标志

  • BUILD SUCCEEDED **

    -> JGSOutDoorClub (0.1.0)

Updating the `51caocao-jiaguoshang-jgsoutdoorclubrepo’ repo

Already up-to-date.

Adding the spec to the `51caocao-jiaguoshang-jgsoutdoorclubrepo’ repo

/usr/bin/gitC/Users/jiaguoshang/.cocoapods/repos/51caocaojiaguoshangjgsoutdoorclubrepostatusporcelain??JGSOutDoorClub/[Add]JGSOutDoorClub(0.1.0) /usr/bin/git -C
/Users/jiaguoshang/.cocoapods/repos/51caocao-jiaguoshang-jgsoutdoorclubrepo
add JGSOutDoorClub
$ /usr/bin/git -C
/Users/jiaguoshang/.cocoapods/repos/51caocao-jiaguoshang-jgsoutdoorclubrepo
commit –no-verify -m [Add] JGSOutDoorClub (0.1.0)
[master 54cf7f6] [Add] JGSOutDoorClub (0.1.0)
1 file changed, 42 insertions(+)
create mode 100644 JGSOutDoorClub/0.1.0/JGSOutDoorClub.podspec

Pushing the `51caocao-jiaguoshang-jgsoutdoorclubrepo’ repo

To http://git.51caocao.cn/jiaguoshang/TestJGs.git
2209fd6..54cf7f6 master -> master

资料相关
CocoaPods的安装与使用(http://www.jianshu.com/p/13cb4937108a
podfile指南(http://guides.cocoapods.org/syntax/podfile.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值