因为项目年后要进行组件化,考虑到公司内部实现的一些私有组件,不对外公开,而又想在不一样项目中使用,该怎么办呢?因为cocoapods有了强大的功能,能够本身建立podspec,更能够设置私有的库。那么利用cocoapods来管理公共组件就很方便了。css
使用Cocoapods制做私有库就完美的解决了这个问题。下图就是使用私有库带给咱们的好处:ios
Cocoapods是如何实现查找第三方库呢?以下图:git
从图中,能够看到经过.podspec能够找到咱们想要的第三方库,那么.spec是什么呢?以下:面试
Pod::Spec.new do |s|服务器
s.name = "JSPatchtest"svn
s.version = "0.0.1"组件化
s.summary = "yoowei 测试利用SVN建立私用库"测试
s.description = <<-DESCurl
yoowei 测试利用SVN建立私用库spa
DESC
s.homepage = "https://www.baidu.com"
s.license = "MIT"
s.author = { "yoowei" => "yoowei@126.com" }
s.platform = :ios, "7.0"
s.source = { :svn => "https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest",:tag => "0.0.1"}
s.source_files = 'yoowei/**/*'
end
至此,咱们明白了查找到第三方库背后的原理。可是,具体如何进行搜索的呢?
先解释一个概念,什么是Spec Repo?它是全部的Pods的一个索引,也就是一个容器(集合),全部公开的Pods都在这个里面。实际上就是一个Git仓库remote端,当你使用了Cocoapods,这个仓库会被clone到本地的~/.cocoapods/repos目录下,进入到这个文件下能够看到master文件夹,就是官方的Spec Repo了。当你pod search的时候就在master这个文件下面查找的。
可是问题来了,咱们公司用的是SVN ,网上的资料介绍的绝大多数是基于git的 ,怎么办?
查找资料发现:
# Specify the location from where the source should be retrieved.
# Supports git, hg, bzr, svn and HTTP.
结果是明确的,支持SVN制做私有库,那么接下来就是不断的踩坑,终于成功了,记录下来备忘,若是可以帮到别人更好。
至于须要SVN帐号密码,在接下来的步骤里面会有设计。
一、我利用JSPatch做为本身的私有库的组件,进项测试,创建以下的目录结构,并提早将JSPatchtest上传到咱们SVN服务器
SVN上面的文件结构(以下)
二、把svn上面对应的JSPatchtest代码check out到本地,cd到JSPatchtest该目录下,使用pod命令建立一个podspec文件。
$ pod spec create JSPatchtest
具体终端操做以下:
$ cd /Users/galahad/Desktop/yoowei
$ svn co https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest
A JSPatchtest/yoowei
A JSPatchtest/yoowei/JPEngine.h
A JSPatchtest/yoowei/JSPatch.js
A JSPatchtest/yoowei/JPEngine.m
Checked out revision 41541.
$ cd /Users/galahad/Desktop/yoowei/JSPatchtest
$ pod spec create JSPatchtest
Specification created at JSPatchtest.podspec
三、打开JSPatchtest.podspec文件,进行修改(不明白的能够先查资料了解)。而后将文件提交到SVN服务器
Pod::Spec.new do |s|
s.name = "JSPatchtest"
s.version = "0.0.1"
s.summary = "yoowei 测试利用SVN建立私用库"
s.description = <<-DESC
yoowei 测试利用SVN建立私用库
DESC
s.homepage = "https://www.baidu.com"
s.license = "MIT"
s.author = { "yoowei" => "yoowei@126.com" }
s.platform = :ios, "7.0"
s.source = { :svn => "https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest"}
s.source_files = 'yoowei/**/*'
end
当咱们用的svn时候,
s.source = { :svn => "https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest"}
细心的你应该发现默认的时候是有一个tags存在的,如今先删掉,后面会叙述。
s.source_files = "yoowei", "yoowei/**/*"
四、使用
刚巧下载了一个LXMySelf的demo,就在这里面试一下
podfile文件描述以下:
target 'LXMySelf' do
pod 'AFNetworking'
pod 'Masonry'
pod 'UITableView+FDTemplateLayoutCell'
pod 'MJRefresh'
pod 'MJExtension'
pod 'MBProgressHUD'
pod 'SDWebImage'
pod 'YYCache'
pod 'SDCycleScrollView'
pod 'JSPatchtest', :svn => 'https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest'
end
注意若是是首次的话,会让你输入SVN权限密码的。(因为刚操做了一遍了,密码已经输入过了)
$ cd /Users/galahad/Desktop/yoowei/LXSelfProject-master
$ pod install
Analyzing dependencies
Pre-downloading: `JSPatchtest` from `https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest`
Downloading dependencies
Using AFNetworking (3.1.0)
Installing JSPatchtest 0.0.1 (was 0.0.1)
Using MBProgressHUD (1.0.0)
Using MJExtension (3.0.13)
Using MJRefresh (3.1.12)
Using Masonry (1.0.1)
Using SDCycleScrollView (1.65)
Using SDWebImage (3.8.1)
Using UITableView+FDTemplateLayoutCell (1.4)
Using YYCache (1.0.3)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There are 10 dependencies from the Podfile and 10 total pods installed.
检查一下,安装成功。
五、补充tag设置
设置tag其实仍是很简单的,我这里使用的是cornrstone管理svn代码。须要在JSPatchtest目录下新建一个tags文件夹,我采用的是本地建立好,而后上传到SVN。
SVN目录结构以下,选中yoowei文件夹右击 Tag ,填写tag和选择tags的位置,以后建立tags.
建立完tags以后的SVN目录结构。
六、再试
podfile文件描述以下:
target 'LXMySelf' do
pod 'AFNetworking'
pod 'Masonry'
pod 'UITableView+FDTemplateLayoutCell'
pod 'MJRefresh'
pod 'MJExtension'
pod 'MBProgressHUD'
pod 'SDWebImage'
pod 'YYCache'
pod 'SDCycleScrollView'
pod 'JSPatchtest', :svn => 'https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest',:tag =>'0.0.1'
end
终端操做:
$ pod install
Analyzing dependencies
Pre-downloading: `JSPatchtest` from `https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest`, tag `0.0.1`
Downloading dependencies
Using AFNetworking (3.1.0)
Installing JSPatchtest 0.0.1 (was 0.0.1)
Using MBProgressHUD (1.0.0)
Using MJExtension (3.0.13)
Using MJRefresh (3.1.12)
Using Masonry (1.0.1)
Using SDCycleScrollView (1.65)
Using SDWebImage (3.8.1)
Using UITableView+FDTemplateLayoutCell (1.4)
Using YYCache (1.0.3)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There are 10 dependencies from the Podfile and 10 total pods installed.
检查安装成功
疑问1?
当tag版本未改变,修改了本地代码,pod install可否更新成功?
若是不能,是否须要将pod file文件中引用该库注释先删除,再添加执行两次pod install?你们能够尝试一下。
或者直接pod update尝试一下
疑问2?
若是咱们本身的组件里面,
s.dependency ' AFNetworking', "~> 3.0.0"
应该在工程文件podfile地方须要先pod AFNetworking。
若是有其余的问题的话,往后慢慢改正。
解决问题的过程当中踩的坑:
一、svn服务器没有设置JSPatchtest的tags,项目podfile文件里面的来源写上了tag 引发的错误
$ pod install
Analyzing dependencies
Pre-downloading: `JSPatchtest` from `https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest`, tag `0.0.1`
[!] Error installing JSPatchtest
[!] /usr/bin/svn export --non-interactive --trust-server-cert --force https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest/tags/0.0.1 /var/folders/rg/gmjp61bx0x95t4tjx2hh_3sr0000gn/T/d20170106-35146-108d7q8
svn: E170000: URL 'https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest/tags/0.0.1' doesn't exist
二、考虑到SVN上面每一个人都有本身的帐号和密码,s.source = { :svn => "https://yoowei@yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest"}是基于个人帐号的,制做的过程当中,我曾经输过密码。假如我将其改为:s.source = { :svn => "https://yoowei.svn.net:443/svn/yoowei/ios/3.0/branches/JSPatchtest"} 会是怎么样的状况呢?通过团队其余人员的测试,不须要密码,一切OK.