1筐眷、pod使用官網(wǎng)的倉(cāng)庫(kù)的關(guān)聯(lián)代碼(這些代碼需要cocoapods審核通過才能被其他人使用掂器,而且每次穩(wěn)定的代碼版本需要打上tag方便使用者選擇對(duì)應(yīng)的tag代碼)
上傳至cocoapods的公開的 倉(cāng)庫(kù) 使用 pod setup
或者 pod install
時(shí)會(huì)從倉(cāng)庫(kù)中下載到本地撇他,存放在電腦的 .cocoapods/repo/master
中召娜,這個(gè)倉(cāng)庫(kù)是cocoapods團(tuán)隊(duì)維護(hù)础钠,大部分開源代碼都放在這里顽悼,當(dāng)然本地放的只是項(xiàng)目的一些相關(guān)信息:
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的項(xiàng)目的Podfile文件說明
Podfile:
platform :ios,'8.0'
use_frameworks!
inhibit_all_warnings!
target 'HDDemo' do
pod 'AFNetworking'
pod 'MJRefresh'
end
2、pod使用本地路徑代碼 (不需要經(jīng)過類似cocoapods審核流程即可使用较木,本地代碼一改红符,pod update即可獲取最新代碼,但是一不小心代碼地址移動(dòng)或者刪除時(shí)伐债,會(huì)有問題)
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地址后萎馅,其他項(xiàng)目即可使用,無審核流程虹蒋,這種模式屬于比較靈活的方式)
Podfile:
platform :ios,'8.0'
use_frameworks!
inhibit_all_warnings!
target 'HDDemo' do
# 只拉取FDDUITableViewDemoSwift/FDDBaseRepo這個(gè)下面的代碼, 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
# 遠(yuǎn)程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使用自己的私有倉(cāng)庫(kù)來替換cocoapods的倉(cāng)庫(kù)魄衅,這樣同樣的不需要審核流程峭竣,自己管理所有的 podsepc文件,需要加上tag來拉取指定的代碼
使用Cocoapods創(chuàng)建私有podspec
-
創(chuàng)建并設(shè)置一個(gè)私有的
Spec Repo
晃虫。這個(gè)倉(cāng)庫(kù)你可以創(chuàng)建私有的也可以創(chuàng)建公開的皆撩,不過既然私有的Spec Repo
,還是創(chuàng)建私有的倉(cāng)庫(kù)吧哲银。創(chuàng)建完成之后在Terminal
中執(zhí)行如下命令# pod repo add [Private Repo Name] [GitHub HTTPS clone URL] $ pod repo add HDPodRepo https://github.com/erduoniba/HDPodRepo.git
此時(shí)如果成功的話進(jìn)入到
~/.cocoapods/repos
目錄下就可以看到HDPodRepo
這個(gè)目錄了扛吞。至此第一步創(chuàng)建私有Spec Repo
完成。 創(chuàng)建
Pod
的所需要的項(xiàng)目工程文件荆责,并且有可訪問的項(xiàng)目版本控制地址滥比。創(chuàng)建
Pod
所對(duì)應(yīng)的podspec
文件。本地測(cè)試配置好的
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 # 私有庫(kù)自動(dòng)生成了最新的代碼
-
在個(gè)人項(xiàng)目中的
Podfile
中增加剛剛制作的好的Pod
并使用。Podfile:
source 'https://github.com/CocoaPods/Specs.git' # 官方庫(kù)地址 source 'https://github.com/erduoniba/HDPodRepo.git' # 私有庫(kù)地址 platform :ios,'8.0' use_frameworks! inhibit_all_warnings! target 'HDDemo' do pod 'FDDUITableViewDemoSwift' # 私有庫(kù)地址里的FDDUITableViewDemoSwift項(xiàng)目 end
?
-
更新維護(hù)
podspec
山憨。$ cd anyPath $ pod repo remove HDPodRepo #刪除本地的私有庫(kù) $ pod repo add HDPodRepo https://github.com/erduoniba/HDPodRepo.git #重新添加私有庫(kù)地址
?
一些錯(cuò)誤:
$ 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
解決:
在倉(cāng)庫(kù)主目錄建立 .swift-version 文件查乒,文件添加 "3.0" 即可
同時(shí)在對(duì)應(yīng)的 FDDUITableViewDemoSwift.podspec 目錄下也添加 .swift-version 文件