podspec中的資源文件
iOS開發(fā)中使用cocoapod做依賴管理, 我們自己很多組件也使用cocoapod私有庫進(jìn)行管理. 在私有庫的開發(fā)中, 總是會面臨私有庫的資源引用的問題.
目前podspec的指引中有如下幾種添加資源的方式:
- resources
- resource_bundles
cocoapod中的方法
一般有如下兩種使用方法:
# 直接使用 resource 和 resources
# 直接會將
spec.resource = 'Resources/HockeySDK.bundle'
spec.resources = ['Images/*.png', 'Sounds/*']
官方文檔注釋是: A list of resources that should be copied into the target bundle, 表示這些資源文件在build時會被直接拷貝到 client target 的 mainBundle 里.
# 生成單個bundle -> MapBox.bundle
spec.ios.resource_bundle = { 'MapBox' => 'MapView/Map/Resources/*.png' }
# 生成多個bundle -> MapBox.bundle, MapBoxOtherResources.bundle
spec.resource_bundles = {
'MapBox' => ['MapView/Map/Resources/*.png'],
'MapBoxOtherResources' => ['MapView/Map/OtherResources/*.png']
}
使用這個方法就能自己定義bundle的名稱以及內(nèi)部封裝的資源. 使用是 'bundle名字' => ['資源路徑']
推薦方法:
s.resource = ['BFTestSDK/Assets/**/*.bundle']
s.resource = ['BFTestSDK/Assets/images/*.png']
s.resource_bundles = {
'BFTestSDK_png' => ['BFTestSDK/Assets/images/*.png'],
'BFTestSDK_voice' => ['BFTestSDK/Assets/voices/*.mp3']
}
第一種, 直接使用自己封裝好的bundle
第二種, 會封裝成兩個bundle -> BFTestSDK_png.bundle 和 BFTestSDK_voice.bundle
注意如果使用靜態(tài)庫, 并且使用pod package BFTestSDK.podspec進(jìn)行打包(默認(rèn)打出來的是靜態(tài)庫), 打包出來的資源文件在BFTestSDK.framework/Resource目錄下, 如果我們要使用, 記得把bundle資源剪切出來.
參考
https://mp.weixin.qq.com/s?__biz=MzA5NzMwODI0MA==&mid=2647759665&idx=1&sn=4b1f2fde434f1b45ff3eac627a7b7fd9
https://blog.csdn.net/TuGeLe/article/details/85049392
http://blog.xianqu.org/2015/08/pod-resources/
https://guides.cocoapods.org/syntax/podspec.html#resources