上传至cocoapods的公开的 仓库 使用 pod setup 或者 pod install 时会从仓库中下载到本地,存放在电脑的 .cocoapods/repo/master 中,这个仓库是cocoapods团队维护,大部分开源代码都放在这里,当然本地放的只是项目的一些相关信息:
CAIStatusBar.podspec.json
{
"name": "CAIStatusBar",
"version": "0.0.1",
"summary": "A simple indicator",
"homepage": "https://github.com/apple5566/CAIStatusBar.git",
"license": "MIT",
"authors": {
"apple5566": "[email protected]"
},
"platforms": {
"ios": "6.0"
},
"source": {
"git": "https://github.com/apple5566/CAIStatusBar.git",
"tag": "0.0.1"
},
"source_files": "CAIStatusBar/**/*.{h,m}",
"resources": "CAIStatusBar/CAIStatusBar.bundle",
"requires_arc": true
}需要使用cocoapods的项目的Podfile文件说明
Podfile:
platform :ios,'8.0'
use_frameworks!
inhibit_all_warnings!
target 'HDDemo' do
pod 'AFNetworking'
pod 'MJRefresh'
endPodfile:
platform :ios,'8.0'
use_frameworks!
inhibit_all_warnings!
target 'HDDemo' do
pod 'AFNetworking', :path => '~/Documents/AFNetworking'
endPodfile:
platform :ios,'8.0'
use_frameworks!
inhibit_all_warnings!
target 'HDDemo' do
# 只拉取FDDUITableViewDemoSwift/FDDBaseRepo这个下面的代码, FDDUITableViewDemoSwift.podspec见下面
pod 'FDDUITableViewDemoSwift/FDDBaseRepo', :git => 'https://github.com/erduoniba/FDDUITableViewDemoSwift.git' ,:tag => '0.1.0'
pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :branch => 'dev'
pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :commit => '082f8319af'
endpod update --verbose --no-repo-update 即可拉取最新代码
Podfile:
platform :ios,'8.0'
use_frameworks!
inhibit_all_warnings!
target 'HDDemo' do
# 远程podspec地址
pod 'FDDUITableViewDemoSwift', :podspec => 'https://raw.githubusercontent.com/erduoniba/FDDUITableViewDemoSwift/master/FDDUITableViewDemoSwift.podspec'
# 本地podspec地址
pod 'FDDUITableViewDemoSwift', :podspec => '/Users/denglibing/project/harryProject/FDDUITableViewDemoSwift/FDDUITableViewDemoSwift.podspec'
endFDDUITableViewDemoSwift.podspec
Pod::Spec.new do |s|
s.name = 'FDDUITableViewDemoSwift'
s.version = "0.1.1"
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'denglibing' => '[email protected]' }
s.summary = 'FDDUITableViewDemoSwift'
s.platform = :ios, '8.0'
s.homepage = "https://github.com/erduoniba/FDDUITableViewDemoSwift"
s.source = { :git => 'https://github.com/erduoniba/FDDUITableViewDemoSwift.git', :tag => "#{s.version}"}
s.module_name = 'FDDUITableViewDemoSwift'
s.framework = 'UIKit'
s.requires_arc = true
# Pod Dependencies
s.subspec 'FDDBaseRepo' do |ss|
ss.source_files = 'FDDUITableViewDemoSwift/FDDBaseRepo/*'
ss.resources = ["FDDUITableViewDemoSwift/FDDBaseRepo/Resources/*"]
ss.dependency 'PullToRefresher'
end
end-
创建并设置一个私有的
Spec Repo。这个仓库你可以创建私有的也可以创建公开的,不过既然私有的Spec Repo,还是创建私有的仓库吧。创建完成之后在Terminal中执行如下命令# pod repo add [Private Repo Name] [GitHub HTTPS clone URL] $ pod repo add HDPodRepo https://github.com/erduoniba/HDPodRepo.git此时如果成功的话进入到
~/.cocoapods/repos目录下就可以看到HDPodRepo这个目录了。至此第一步创建私有Spec Repo完成。 -
创建
Pod的所需要的项目工程文件,并且有可访问的项目版本控制地址。 -
创建
Pod所对应的podspec文件。 -
本地测试配置好的
podspec文件是否可用。(不合格问题也不大) -
向私有的
Spec Repo中提交podspec。$ cd path/FDDUITableViewDemoSwift.podspec $ pod repo push HDPodRepo FDDUITableViewDemoSwift.podspec #前面是本地Repo名字 后面是podspec名字 # 成功之后 $ cd /Users/denglibing/.cocoapods/repos/HDPodRepo $ tree . ├── FDDUITableViewDemoSwift │ ├── 0.1.1 │ │ └── FDDUITableViewDemoSwift.podspec │ └── 0.1.2 │ └── FDDUITableViewDemoSwift.podspec └── README.md # 私有库自动生成了最新的代码
-
在个人项目中的
Podfile中增加刚刚制作的好的Pod并使用。Podfile:
source 'https://github.com/CocoaPods/Specs.git' # 官方库地址 source 'https://github.com/erduoniba/HDPodRepo.git' # 私有库地址 platform :ios,'8.0' use_frameworks! inhibit_all_warnings! target 'HDDemo' do pod 'FDDUITableViewDemoSwift' # 私有库地址里的FDDUITableViewDemoSwift项目 end
-
更新维护
podspec。$ cd anyPath $ pod repo remove HDPodRepo #删除本地的私有库 $ pod repo add HDPodRepo https://github.com/erduoniba/HDPodRepo.git #重新添加私有库地址
一些错误:
$ pod lib lint --verbose --no-clean --allow-warnings
We get the error below:
** BUILD FAILED **
The following build commands failed:
CompileSwift normal x86_64 /var/folders/yg/dlxwsn292j108t5qtlmgbtfh0000gn/T/CocoaPods/Lint/Pods/ReachabilitySwift/Reachability/Reachability.swift
CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
(2 failures)
...
...
...
Pods workspace available at /var/folders/yg/dlxwsn292j108t5qtlmgbtfh0000gn/T/CocoaPods/Lint/App.xcworkspace for inspection.
[!] Teste did not pass validation, due to 69 errors.ashleymills/Reachability.swift#146
解决:
在仓库主目录建立 .swift-version 文件,文件添加 "3.0" 即可
同时在对应的 FDDUITableViewDemoSwift.podspec 目录下也添加 .swift-version 文件