1. 常用指定使用
1.1 指定庫使用的 Swift 版本
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == 'ActiveLabel'
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.2'
end
end
end
end
target 'MyTarget' do
use_frameworks!
# Post installation script that enables the Swift 4.2 compiler's
# legacy 4.1 mode for 4.2-incompatible pods
post_install do |installer|
incompatiblePods = ['PodA', 'PodB']
installer.pods_project.targets.each do |target|
if incompatiblePods.include? target.name
target.build_configurations.each do |config|
# Replace with whichever Swift version you're migrating from
config.build_settings['SWIFT_VERSION'] = '4.1'
end
end
end
end
pod 'XXXX'
pod 'XXXX'
end
可以通過 Podfile 設(shè)置舊的還沒支持 Swift4 的庫指定用 Swift3.2 編譯区赵。
當(dāng)然也可以一個個的在 Target 的 Build Settings 中設(shè)置 Swift complie language version
1.2 指定在 Debug 下安裝庫
pod 'GDPerformanceView-Swift', '~> 1.2.0', :configurations => ['Debug']
1.3 指定 Master等分支版本
pod 'ActiveLabel', :git => 'https://github.com/optonaut/ActiveLabel.swift', :branch => 'master'
1.4 指定本地目
pod 'ICSMainFramework', :path => "./Library/ICSMainFramework/"
2. 發(fā)布 CocoaPod 庫
1.如果已經(jīng)本地已經(jīng)有了建好的 CocoaTouchFrameWork 的 project,那可以在項目目錄下執(zhí)行:
pod spec create YourFrameworkName
如果本地沒有建好的project可以執(zhí)行:
pod lib create YourFrameworkName
- 編輯該目錄下自動創(chuàng)建好的
YourFrameworkName.podsepc
文件 - 發(fā)布庫:
- Github 上創(chuàng)建好庫玄糟;
- clone 到本地,并把之前的代碼拷貝到次 clone 的目錄怔蚌;
- 更新
.podsepc
文件里對應(yīng)的 git URL 為你在 Github 的地址
s.source = { :git => "https://github.com/xxx/xxx.git", :tag => "#{s.version}" }
- 把代碼 push 上去勇劣;
- 打標(biāo)記
git tag 0.1.0 git push --tags
- 注冊 truck
pod trunk register xxx@xxx.com 'xxxxx'
- 上面 truck register 會發(fā)一封郵件給你,去郵件里驗證跋理。然后就可以
pod trunk push --allow-warnings
- 管理庫:
查看自己的信息
添加管理維護(hù)者pod trunk me
查看庫信息pod trunk add-owner [庫的名字] [新管理者的郵件] pod trunk remove-owner [庫名] [郵件]
小結(jié):pod trunk info [庫名]
在驗證和上傳你的podspec文件到trunk之前,需要將你的源碼push到Github上恬总,tag一個版本號并發(fā)布一個release版本前普,這樣podspec文件中的s.source的值才能是準(zhǔn)確的: git add -A && git commit -m "Release 1.0.1." git tag '1.0.1' git push --tags git push origin master 這兩條命令是為pod添加版本號并打上tag: set the new version to 1.0.1 set the new tag to 1.0.1
- 更新發(fā)布:
- 修改podspec文件tag版本號,也就是修改s.version的值壹堰,提交修改后的代碼和podspec文件到Github倉庫拭卿,重新發(fā)布一個Release版本
- 進(jìn)入項目根目錄,校驗podspec文件贱纠,校驗成功后峻厚,重新push podspec文件到CocoaPods官方倉庫,命令如下:
pod cache clean --all // 清除pod緩存 pod lib lint xxx.podspec --allow-warnings // 校驗 pod trunk push xxx.podspec --allow-warnings // 提交到CocoaPods官方倉庫
遇到問題:
pod lib lint 在本地執(zhí)行是成功的
但是在 pod trunk push 的時候一直報錯:
`source_files` pattern did not match any file.
后來把文件路徑修改為以.git文件所在級別后谆焊,本地lib lint不成功惠桃,但是push卻成功
"Source/*.{h,m,swift}"修改成:
"HSCycleGalleryView/**/*.{h,m,swift}"
本人預(yù)測是pod lib lint 檢測的source_files是針對本地.podspec所在的文件目錄;而pod tunk push是檢測github上的文件目錄
#可以詳細(xì)輸出日志信息
pod trunk push xx.podspec --verbose
podspec文件指定Swift版本:
s.swift_version = '>= 3.2, <= 4.0'
3. SVN 私有庫
按照SVN 工作流規(guī)范辖试,在項目名稱目錄下建立三個文件夾
- branches
- tags
- trunk
root
|-- trunk
|-- branches
| |-- v1.0-dev
| |-- v1.0-stage
| |-- v2.1-dev
| |-- v2.1-stage
| |-- v2.1.1-stage
| `-- ...
`-- tags
|-- v1.0.0
|-- v1.1.0
|-- v1.1.1
|-- v2.0.0
`-- ...
在下面目錄下 pod lib create XXX
/Users/Hanson/Desktop/ios-svn/ios-app/DingdongExtensionKit/trunk/
當(dāng)庫開發(fā)完成后辜王,利用svn工具(比如cornerstone),在右擊runk
目錄建立 tag
比如 0.1.1
# DingdongExtensionKit.podspec
Pod::Spec.new do |s|
s.name = "DingdongExtensionKit"
s.version = "0.1.1"
s.summary = "DingdongExtensionKit."
s.homepage = "https://github.com/zyphs21/"
s.author = { "zyphs21" => "hansenhs21@live.com" }
# 注意這里使用 svn=> 以及指向之前 創(chuàng)建的tag
s.source = { :svn => "http://dev.vanyun.cn:8000/svn/vanyun/Dingdong/Projects/ios-app/DingdongExtensionKit/", :tag => s.version.to_s }
s.source_files = "DingdongExtensionKit/**/*.{swift}"
end
這個庫就算創(chuàng)建好了罐孝,使用的時候在Podfile
里
# pod 'DingdongUserKit', :path => '/Users/Hanson/Desktop/ios-svn/ios-app/DingdongUserKit/trunk/'
pod 'DingdongExtensionKit', :svn => 'http://dev.vanyun.cn:8000/svn/vanyun/Dingdong/Projects/ios-app/DingdongExtensionKit/', :tag => '0.1.1'
4. Pod 里加入圖片資源
Pod::Spec.new do |s|
s.name = "YMPhotoBrowser"
s.version = "1.0.0"
s.summary = "YMPhotoBrowser is a modern looking photo gallery written in Swift for iOS."
s.homepage = "https://github.com/zyuanming/YMPhotoBrowser"
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { "zyuanming" => "zyuanming@outlook.com" }
s.swift_version = '4.0'
s.ios.deployment_target = '8.0'
s.source = { :git => "https://github.com/zyuanming/YMPhotoBrowser.git", :tag => "#{s.version}" }
s.source_files = "YMPhotoBrowser/*"
# 使用Resource Bundle
s.resource_bundles = { 'Image' => ['YMPhotoBrowser/Resources/*.png']}
s.dependency 'Kingfisher', '~> 4.5.0'
end
然后使用圖片的時候:
let frameworkBundle = Bundle(for: type(of: self))
// 這里對應(yīng) s.resource_bundles = { 'Image' => ['YMPhotoBrowser/Resources/*.png']}
let resourceBundleURL = frameworkBundle.url(forResource: "Image", withExtension: "bundle")
let resourceBundle = Bundle(url: resourceBundleURL!)
let image = UIImage(named: "photo_dismiss", in: resourceBundle, compatibleWith: nil)
5. Pod Update和outdated
每當(dāng)你運行pod outdated
命令時呐馆,CocoaPods
會列出所有在Podfile.lock
中的有新版本的pod庫。這意味著當(dāng)你對這些 pod
使用 pod update PODNAME
時莲兢,他們會更新(只要新版本仍然遵守你在Podfile中做的類似于pod 'MyPod', '~>x.y'這樣的限制)
6. 版本號指定
= 0.1 Version 0.1.
> 0.1 Any version higher than 0.1.
>= 0.1 Version 0.1 and any higher version.
< 0.1 Any version lower than 0.1.
<= 0.1 Version 0.1 and any lower version.
~> 0.1.2 Version 0.1.2 and the versions up to 0.2, not including 0.2. This operator works based on the last component that you specify in your version requirement. The example is equal to >= 0.1.2 combined with < 0.2.0 and will always match the latest known version matching your requirements.
~> 0.1.3-beta.0 Beta and release versions for 0.1.3, release versions up to 0.2 excluding 0.2. Components separated by a dash (-) will not be considered for the version requirement.
A list of version requirements can be specified for even more fine grained control.