https://www.cnblogs.com/lxlx1798/p/14587007.html
一,概述
spec文件
描述了Pod庫
的版本。它包括有關從哪里獲取source
、要使用哪些文件、應用程序構建設置以及其他通用元數據(如名稱、版本和描述)的詳細信息。
二、spec
文件(Specification) 規范說明
1.創建spec
文件
pod spec create DemoSpec
2.podspec
示例
Pod::Spec.new do |spec|
spec.name = 'Reachability'
spec.version = '3.1.0'
spec.license = { :type => 'BSD' }
spec.homepage = 'https://github.com/tonymillion/Reachability'
spec.authors = { 'Tony Million' => 'tonymillion@gmail.com' }
spec.summary = 'ARC and GCD Compatible Reachability Class for iOS and OS X.'
spec.source = { :git => 'https://github.com/tonymillion/Reachability.git', :tag => 'v3.1.0' }
spec.module_name = 'Rich'
spec.ios.deployment_target = '9.0'
spec.osx.deployment_target = '10.10'
spec.source_files = 'Reachability/common/*.swift'
spec.ios.source_files = 'Reachability/ios/*.swift', 'Reachability/extensions/*.swift'
spec.osx.source_files = 'Reachability/osx/*.swift'
spec.framework = 'SystemConfiguration'
spec.ios.framework = 'UIKit'
spec.osx.framework = 'AppKit'
spec.dependency 'SomeOtherPod'
end
語法
1、Root specification
根規范“根”規范存儲有關庫的特定版本的信息。此組中的屬性只能寫入根
規范,而不是子規范
。在這個組中列出的屬性是podspec
需要的唯一屬性。其他組的屬性被用來改進podspec
并遵循一個關于配置方法的約定。根規范可以直接通過sub-specifications
來描述這些屬性。
name
必須
#跟podspec文件名相同
spec.name = 'AFNetworking'
version
必須
spec.version = '0.0.1'
cocoapods_version
規范支持的CocoaPods版本。
spec.cocoapods_version = '>= 0.36'
authors
必須
庫維護人員的名稱和電子郵件地址,不是Podspec維護者。
spec.author = '作者名字'
多個作者
spec.authors = 'Darth Vader', 'Wookiee'
多個作者
,以及其郵箱
spec.authors = { 'Darth Vader' => 'darthvader@darkside.com', 'Wookiee' => 'wookiee@aggrrttaaggrrt.com' }
license
必須
pod庫
的許可證。除非源文件包含一個名為LICENSE.* or LICENCE.*
的文件,否則許可證文件的路徑或通常用于許可證類型的公告完整文本,必須指定。許可證文件可以沒有文件擴展名也可以是txt, md
, 或是markdown
,
許可證默認與spec
文件在同一目錄下
MIT
是一個比較寬泛的開源許可協議
spec.license = 'MIT'
指定許可文件
spec.license = { :type => 'MIT', :file => 'MIT-LICENSE.txt' }
指定了許可證文件的內容
spec.license = { :type => 'MIT', :text => <<-LICENSE Copyright 2012 Permission is granted to... LICENSE }
homepage
必須
pod庫
主頁地址
spec.homepage = 'http://www.example.com'
source
必須
pod庫的位置
通過tag
指定Git源
用的最多的方式!!
tag值
與spec.version
一致。
spec.source = { :git => 'https://github.com/AFNetworking/AFNetworking.git', :tag => spec.version.to_s }
以下的方式,項目中沒有用到,不能過多的解釋,更多參照source
使用v前綴的tag值和子模塊`
spec.source = { :git => 'https://github.com/typhoon-framework/Typhoon.git', :tag => "v#{spec.version}", :submodules => true }
#使用svn源
spec.source = { :svn => 'http://svn.code.sf.net/p/polyclipping/code', :tag => '4.8.8' }
#使用HTTP下載代碼的壓縮文件。它支持zip、tgz、bz2、txz和tar。
spec.source = { :http => 'http://dev.wechatapp.com/download/sdk/WeChat_SDK_iOS_en.zip' }
#使用HTTP下載文件,使用hash來驗證下載。它支持sha1和sha256。
spec.source = { :http => 'http://dev.wechatapp.com/download/sdk/WeChat_SDK_iOS_en.zip',:sha1 => '7e21857fe11a511f472cfd7cfa2d979bd7ab7d96' }
支持的key
:
:git => :tag, :branch, :commit, :submodules
:svn => :folder, :tag, :revision
:hg => :revision
:http => :flatten, :type, :sha256, :sha1
:path
summary
必須
pod庫
簡介,最多140
個字符。
spec.summary = 'Computes the meaning of life.'
description
pod庫的描述,比summary詳細
spec.description = <<-DESC
Computes the meaning of life.
Features:
1. Is self aware
...
42. Likes candies.
DESC
screenshots
用圖片展示pod庫,UI庫可以使用這種方式,其他的建議使用git地址
單個截圖
spec.screenshot = 'http://dl.dropbox.com/u/378729/MBProgressHUD/1.png'
多個截圖
spec.screenshots = [ 'http://dl.dropbox.com/u/378729/MBProgressHUD/1.png', 'http://dl.dropbox.com/u/378729/MBProgressHUD/2.png' ]
documentation_url
可選的Pod庫
文檔的URL
。
spec.documentation_url = 'http://www.example.com/docs.html'
prepare_command
在Pod
下載完之后將執行的bash腳本
。該命令可用于創建、刪除和修改任何下載的文件。
這個命令是在Pod
被清理之前且創建Pod
項目之前執行的。工作目錄是Pod
的根目錄
。
如果是使用:path
安裝的pod
,這個命令將不會被執行。
指定腳本文件,ruby build_files.rb
是腳本文件名
spec.prepare_command = 'ruby build_files.rb'
這里用到了ruby命令
`#sed命令是利用script來處理文本文件
#i :插入
#s :取代
#sed 's/要被取代的字串/新的字串/g'
#第一個sed 語句表示將當前目錄下的所有.h文件中的MyNameSpacedHeader替換成Header`
spec.prepare_command = <<-CMD
sed -i 's/MyNameSpacedHeader/Header/g' ./**/*.h
sed -i 's/MyNameOtherSpacedHeader/OtherHeader/g' ./**/*.h
CMD
deprecated
是否棄用
spec.deprecated = true
deprecated_in_favor_of
設置棄用的pod庫的新名字,告訴使用者可以搜索新的庫名。
spec.deprecated_in_favor_of = 'NewMoreAwesomePod'
2、Platform
規范應該指出使用pod支持的平臺和相應的部署目標。如果沒有在子規范中定義,該分組的屬性將繼承父類的值。
platform
不設置表示支持全部平臺,如果支持多個平臺使用deployment_target命令
只能在OS系統使用,要求系統版本至少10.8
spec.platform = :osx, '10.8'
也可以只指定平臺,不指定版本
spec.platform = :iOS
deployment_target
平臺支持的最低部署版本,可以分別為每個平臺指定不同的版本。
spec.ios.deployment_target = '6.
spec.osx.deployment_target = '10.8'
3、Build settings
接下來列出了與構建庫所用的構建環境相關的屬性。
dependency
設置對其他pod或“sub-specification”的依賴。
依賴關系如果需要指定版本,推薦使用~>
spec.dependency 'AFNetworking', '~> 1.0'
依賴RestKit庫中的子模塊
spec.dependency 'RestKit/CoreData', '~> 0.20.0'
指定某個平臺的依賴
spec.ios.dependency 'MBProgressHUD', '~> 0.5'
requires_arc
支持多平臺
requires_arc允許指定哪個source_files使用ARC。不使用ARC的文件將添加- fno-objc- ARC編譯器標記。
此屬性的默認值為true。
不支持ARC
spec.requires_arc = false
指定某個文件夾支持ARC的
spec.requires_arc = 'Classes/Arc'
指定某些文件支持ARC
spec.requires_arc = ['Classes/*ARC.m', 'Classes/ARC.mm']
frameworks 支持多平臺
需要鏈接的系統frameworks
spec.ios.framework = 'CFNetwork'
多個庫
spec.frameworks = 'QuartzCore', 'CoreData'
libraries 支持多平臺
spec.ios.library = 'xml2'
#多個庫,其中xml2對應ibxml2.tbd z對應libz.tbd
#所以lib庫 省略lib與后綴。
spec.libraries = 'xml2', 'z'
compiler_flags
支持多平臺
編譯參數 #-D是前綴,-Wno-format這個是gcc編譯警告的參數
spec.compiler_flags = '-DOS_OBJECT_USE_OBJC=0', '-Wno-format'
pod_target_xcconfig
支持多平臺
設置的參數都會添加到最終的私有pod的target xcconfig文件中
【注意】這是設置pod庫的target 命令
#OTHER_LDFLAGS 對應buildsetting的other linker flags
spec.pod_target_xcconfig = { 'OTHER_LDFLAGS' => '-lObjC' }
user_target_xcconfig
支持多平臺
這個會添加到最終target 的xcconfig中,不建議使用,不應該污染用戶項目的構建設置,因為這可能導致沖突。
如果導入pod時,需要使用clang編譯器標志或預編譯器宏定義,最好使用pod_target_xcconfig,這個只會影響你自己的pod target。
spec.user_target_xcconfig = { 'MY_SUBSPEC' => 'YES' }
spec.user_target_xcconfig = { 'MY_SUBSPEC' => 'YES' }
prefix_header_contents
支持多平臺
在pod項目的前綴頭文件中注入的內容,前綴頭文件是模塊的pch文件。
spec.prefix_header_contents = '#import <UIKit/UIKit.h>'
spec.prefix_header_contents = '#import <UIKit/UIKit.h>', '#import <Foundation/Foundation.h>'
//可以將多行內容放到兩個EOS中間
s.prefix_header_contents = <<-EOS
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#else
EOS
s.prefix_header_contents = <<-EOS
#define HHHH @"測試代碼"
EOS