1、pod使用官網的倉庫的關聯代碼(這些代碼需要cocoapods審核通過才能被其他人使用,而且每次穩定的代碼版本需要打上tag方便使用者選擇對應的tag代碼)
上傳至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": "zaijiank110@sohu.com"
},
"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'
end
2、pod使用本地路徑代碼 (不需要經過類似cocoapods審核流程即可使用,本地代碼一改,pod update即可獲取最新代碼,但是一不小心代碼地址移動或者刪除時,會有問題)
Podfile:
platform :ios,'8.0'
use_frameworks!
inhibit_all_warnings!
target 'HDDemo' do
pod 'AFNetworking', :path => '~/Documents/AFNetworking'
end
3、pod使用源碼地址的代碼(每次pod update即可獲取給定地址的最新代碼,也可以選擇指定的tag,源碼每次push到git地址后,其他項目即可使用,無審核流程,這種模式屬于比較靈活的方式)
Podfile:
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'
end
pod update --verbose --no-repo-update 即可拉取最新代碼
4、pod使用podspec文件來拉取代碼:
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'
end
FDDUITableViewDemoSwift.podspec
Pod::Spec.new do |s|
s.name = 'FDDUITableViewDemoSwift'
s.version = "0.1.1"
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'denglibing' => 'denglibing@fangdd.com' }
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
5、pod使用自己的私有倉庫來替換cocoapods的倉庫,這樣同樣的不需要審核流程,自己管理所有的 podsepc文件,需要加上tag來拉取指定的代碼
-
創建并設置一個私有的
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.
https://github.com/ashleymills/Reachability.swift/issues/146
解決:
在倉庫主目錄建立 .swift-version 文件,文件添加 "3.0" 即可
同時在對應的 FDDUITableViewDemoSwift.podspec 目錄下也添加 .swift-version 文件