Cocoapods是非常好用的一個(gè)iOS依賴管理工具,使用它可以方便的管理和更新項(xiàng)目中所使用到的第三方庫,本節(jié)介紹如何將自己的組件代碼交由它去管理。
創(chuàng)建Git倉庫
根據(jù)GitHub提示操作即可,建立自己的Git倉庫。
創(chuàng)建podspec文件
終端直接執(zhí)行以下命令,創(chuàng)建Pod項(xiàng)目工程文件,例如要?jiǎng)?chuàng)建一個(gè)叫做 LTChat 的Pod工程,命令執(zhí)行成功后,會(huì)看到一個(gè)叫做 LTChat.podspec 的文件。
pod spec create "LTChat"

編輯podspec文件
編輯文件時(shí)注意編輯工具的使用,Mac上默認(rèn)的文本編輯文件編輯時(shí)很容易出現(xiàn)編碼問題。
修改Pod文件的配置信息,摘要如下:
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.name = "LTChat"
s.version = "0.0.1"
# summary 總結(jié)
s.summary = "Chat use XMPP framework and WebRTC framework."
# description 描述,與summary不能相同
s.description = <<-DESC
基于XMPP和WebRTC框架進(jìn)行聊天組件。
DESC
s.homepage = "https://github.com/l900416/LTChat"
# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.license = "MIT"
# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.platform = :ios, "8.0"
# When using multiple platforms
s.ios.deployment_target = "8.0"
# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.source = { :git => "https://github.com/l900416/LTChat.git", :tag => "#{s.version}" }
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.source_files = "LTChat", "LTChat/**/*.{h,m}"
s.exclude_files = "LTChat/Exclude"
s.public_header_files = "LTChat/**/*.h"
# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
s.resources = "LTChat/**/*.{xib}","LTChat/**/*.{png}"
# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
# s.frameworks = "SomeFramework", "AnotherFramework"
# s.libraries = "iconv", "xml2"
# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
# s.requires_arc = true
s.dependency "XMPPFramework", "~> 3.7.0"
s.dependency "GoogleWebRTC"
建立TAG
使用 git tag 和 git push 命令建立TAG

驗(yàn)證Pod文件
使用 pod lib lint 或 pod spec lint 驗(yàn)證Pod文件格式是否正確,可以添加 --verbose 獲取更多的信息,添加 --no-clean 不對驗(yàn)證的工程進(jìn)行清理,方便查看工程驗(yàn)證錯(cuò)誤原因。兩者的區(qū)別:
- pod lib lint 是只從本地驗(yàn)證pod是否能夠通過驗(yàn)證
- pod sepc lint 是從本地和遠(yuǎn)程來驗(yàn)證pod是否通過驗(yàn)證。
發(fā)布
使用 pod trunk 發(fā)布程序,使用到的命令如下:
- pod trunk register 郵箱 '用戶名':注冊,之后在郵件中進(jìn)行驗(yàn)證。
- pod trunk me : 查看個(gè)人信息,包括該郵件下已經(jīng)注冊的代碼組件、個(gè)人信息、登陸session等。
- pod trunk push *.podspec : 發(fā)布podspec
- 等待審核
- pod search: 檢查是否發(fā)布成功
更新
建立TAG,并發(fā)布。


問題記錄
pod lib lint驗(yàn)證失敗
如果出現(xiàn)驗(yàn)證失敗,則需要添加參數(shù) --verbose 查看詳細(xì)錯(cuò)誤原因 。例如
The following build commands failed:
Ld /Users/liangtong/Library/Developer/Xcode/DerivedData/App-eowwjkrvluwvfdhhkljszfucgimo/Build/Intermediates.noindex/Pods.build/Release-iphonesimulator/LTChat.build/Objects-normal/i386/LTChat normal i386
(1 failure)
[!] LTChat did not pass validation, due to 1 error and 71 warnings.
原因是由于谷歌官方iOS版本的 GoogleWebRTC 僅支持處理器x86_64 armv7 arm64導(dǎo)致
Swift Language Version
根據(jù)失敗的log日志,確認(rèn)失敗原因,比如LTChat依賴于XMPPFramework,而XMPPFramework又依賴了KissXML。此時(shí)編譯的時(shí)候出現(xiàn)了Swift版本不明確的錯(cuò)誤。
=== BUILD TARGET KissXML OF PROJECT Pods WITH CONFIGURATION Release ===
Check dependencies
The “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift. This setting can be set in the build settings editor.
The “Swift Language Version” (SWIFT_VERSION) build setting must be set to a supported value for targets which use Swift. This setting can be set in the build settings editor.
** BUILD FAILED **
The following build commands failed:
Check dependencies
解決辦法,指定 Swift Language 版本
pod lib lint --swift-version=4.0
上傳后查詢不到最新版本
解決辦法:清理緩存,重新setup
rm -rf ~/.cocoapods/repos/master
pod setup