本地私有库有存在问题
1.需要主动指明路径 如果调整路径,需要修改相关配置
2.版本升级不好维护
3.不利于多人开发
1.登录coding.net
- 因为gitHub虽然可以开放了私有库但是限制了合作人数,只能小团队开发
- 使用coding.net
- 注册coding.net 账号
2.创建私有库
- 完成仓库创建
- 查看地址 复制地址
进行管理
- 终端打开
- pod repo add XXX 地址
- 用https 后再输入自己的账号密码就可以了 注意 username 是账号 (邮箱地址)不要输入自己的昵称
- 所以我用的是ssh 公钥地址 报错了 是因为我没有配置 ssh
配置公钥
- 终端 输入 ssh-keygen
- 输入电脑密码 两次
- 然后在.SSH文件里面就会产生id_rsa和id_rsa.pub两个文件,路径如下:
coding.net 配置公钥
- 个人账户 新增公钥
- 然后我们把id_rsa.pub公钥的内容加进去 公钥内容里面,如图所示,添加成功
创建私有远程仓库
- 1.创建私有库的索引库:存放spec文件的地方,用于索引到代码的位置
- 2.创建私有库的代码库:存放真正的组件代码的地方
将创建的索引库添加到本地cocoapods仓库
终端 重新输入
pod repo add WLFSpecs 远程索引仓库地址
- pod repo 发现已经添加成功
创建本地的pod模板库
- cd 到空的文件夹
- pod lib create WLFBase
- 创建一个Example工程
- 替换核心代码
- cd 到Example
- pod install
- 修改podspec 文件 把hompage 和 source 修改正确
- 如下
Pod::Spec.new do |s|
s.name = 'WLFBase'
s.version = '0.1.0'
s.summary = 'WLFBase.'
s.description = <<-DESC
WLFBase.基础库,分类等
DESC
s.homepage = 'https://wlfade.coding.net/p/xxx/d/xxx/git'
# s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Wlfade' => 'xxxx@qq.com' }
s.source = { :git => 'https://e.coding.net/xxx/xxx/WLFBase.git', :tag => s.version.to_s }
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
s.ios.deployment_target = '9.0'
s.source_files = 'WLFBase/Classes/**/*'
# s.resource_bundles = {
# 'WLFBase' => ['WLFBase/Assets/*.png']
# }
# s.public_header_files = 'Pod/Classes/**/*.h'
# s.frameworks = 'UIKit', 'MapKit'
# s.dependency 'AFNetworking', '~> 2.3'
end
- pod lib lint 验证podspec 是够通过 XXXLib passed validation 认证成功
pod lib lint参数解析:
--sources:需要引⽤的spec,默认只依赖master,如果当前pod依赖了私有库,需要将其对应的spec包含进来,不然会报找不到对应库的问题。参数可以是本地spec的名称,也可以是git地址。
--allow-warnings:有警告会通过不了,如果警告是⽆关紧要的,可以加上,让检测通过。 --verbose:打印详细的检验过程
--use-libraries:⼯程或者依赖⾥⾯了静态库(*.a⽂件)或者是framework pod lib lint 表示在本地校验索引文
pod spec lint 表示在本地和远程都校验索引文件
提交自己写的WLFBase组件代码到远程私有仓库中
方法1
- clone 代码到新的空的文件夹
git clone 组件仓库地址
- 把之前做的那个这些文件复制过去
- git add . //添加代码到缓存区
- git commit -m '1' //提交
- git push 提交远程仓库
方法2
-
git add .
-
git commit -m '注释'
-
git remote add origin 组件仓库地址.git
-
git remote
-
git push origin master //这个可能会失败
-
git push -f orgin master //强制推送
-
pod spec lint //验证远程仓库 但是现在还是不成功的因为没有打tag
提交标签
- git tag '0.1.0' //和podspec 保持一致
- git tag /显示0.1.0 说明本地有个标签了 这里的tag 要和 podspecs 保持一致 不让不会成功的
- git push --tags
- 这里就多了一个tag
- pod spec lint //验证远程仓库
- 显示 xxx.podspec passed validation.说明成功
向私有索引库提交podspec
- pod repo push WLFSpecs WLFBase.podspec //这里其实会自动校验podspec 的远程验证
- 说明已经创建私有组件库和私有索引库已经成功了
使用
- 重新创建一个测试项目 test
- 创建podfile
source 'https://e.coding.net/xxx/xxx/xxx.git' //远程私有索引库地址
source 'https://cdn.cocoapods.org/'
platform :ios, '9.0'
target 'Test' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
pod 'WLFBase' //pod 组件名
end
- pod install
- 导入成功使用
关于cocoapod 1.8.0之后版本的变化
blog.csdn.net/fongim/arti…
sudo gem uninstall cocoapods
sudo gem install cocoapods -v 1.7.5
我是直接安装了老版本的
优化升级
- 添加代码到本地的代码组建仓库的 Classes
- 修改podspecs 版本号为 '0.2.0'
- git add .
- git commit -m '优化升级'
- git push origin master
- 组件代码库提交成功
- git tag '0.2.0'
- git push --tags
- pod spec lint --allow-warnings //取出警告验证
- pod repo push WLFSpecs WLFBase.podspec --allow-warnings //去除警告推送同步到本地仓库和远程仓库
使用最新的版本前 需要更新一下
- pod update --no-repo-update
- pod install
当自己提交的组件代码引用了其他的第三方库
- podspec文件中这个要写上
source 'https://e.coding.net/wlfade/wlfprivatelib/WLFSpecs.git'
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
target 'Test' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
pod 'WLFBase'
#pod 'SDWebImage'
pod 'AFNetworking'
end
私有库创建分支
- 修改Spec文件
# s.source_files = 'WLFBase/Classes/**/*'
s.subspec 'Base' do |b|
b.source_files = 'WLFBase/Classes/Base/**/*'
end
s.subspec 'Category' do |c|
c.source_files = 'WLFBase/Classes/Category/**/*'
end
s.subspec 'Network' do |n|
n.source_files = 'WLFBase/Classes/Network/**/*'
n.dependency 'AFNetworking'
end
s.subspec 'Tool' do |t|
t.source_files = 'WLFBase/Classes/Tool/**/*'
end
- 哪个分类使用了依赖库,依赖库的dependency 就写到哪个分类中
- 修改版本号 0.4.0
- git add .
- git commit -m '1'
- git push origin master
- git tag '0.4.0'
- git push --tags
- pod repo push WLFSpecs WLFBase.podspec --allow-warnings
source 'https://e.coding.net/wlfade/wlfprivatelib/WLFSpecs.git'
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
target 'Test' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
pod 'WLFBase/Category'
pod 'AFNetworking'
pod 'WLFBase', :subspecs => ['Base','Category'] //或者
end
- pod install
图片依赖
- 将图片资源存放在这
- podspec 修改加上这句
s.resource_bundles = {
'WLFMain' => ['WLFMain/Assets/*.png']
}
- 组件化的视图如果是加载xib文件的 如:
- 加载xib就需要修改成这样
// NSBundle *mainBundle = [NSBundle mainBundle];
NSBundle *currenBundle = [NSBundle bundleForClass:self];
XMGMiddleView *middleView = [[currenBundle loadNibNamed:@"XMGMiddleView" owner:nil options:nil] firstObject];
return middleView;
- 还有里面的控件使用图片 要加上 XXX.bundle
- 还有图片名字要补全 @2x.png 也要写上
NSBundle *currentBundle = [NSBundle bundleForClass:[self class]];
NSString *imagePath = [currentBundle pathForResource:@"tabbar_bg@2x.png" ofType:nil inDirectory:@"WLFMain.bundle"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
self.backgroundImage = image;
- 查看图片的具体bundle位置
- 这个才是具体的bundle文件位置,显示包内容就可以查看了
- 修改完上述的问题之后 最后 pod install
- 出现问题改完一个都要重新 pod install 一下重新编译才能实现