cocoapods系列教程---安裝與使用
cocoapods系列教程---Podfile文件
cocoapods系列教程---Podfile.lock文件 和 Spec Repo
cocoapods系列教程---spec文件
cocoapods系列教程---原理篇
cocoapods系列教程---讓自己的開源框架支持cocoapods
cocoapods系列教程---模塊化設計
cocoapods系列教程---創(chuàng)建私有pods
下面介紹spec文件的詳細設置.基本上是根據(jù)官網(wǎng)翻譯過來的,有什么不對還望指點
- name
spec.name = 'AFNetworking'
- 版本
spec.version = '0.0.1'
- 支持的cocoapods的版本
spec.cocoapods_version = '>= 0.36'
- 配置信息,根據(jù)個人需要填寫
spec.xcconfig = { 'HEADER_SEARCH_PATHS' => '$(SDKROOT)/usr/include/libxml2' }
spec.xcconfig = { 'FRAMEWORK_SEARCH_PATHS' => '"
$(SRCROOT)/libs/Frameworks/Huoyan"' }
spec.xcconfig = { 'LIBRARY_SEARCH_PATHS' => '"$(PODS_ROOT)/iOS_Util/iOS_Util/AMR/lib"' }
spec.xcconfig = { "HEADER_SEARCH_PATHS" => "${PODS_ROOT}/boost" }
- 作者信息
spec.author = 'Darth Vader'
若果有多個作者,可以這樣寫
spec.authors = 'Darth Vader', 'Wookiee'
spec.authors = { 'Darth Vader' => 'darthvader@darkside.com',
'Wookiee' => 'wookiee@aggrrttaaggrrt.com' }
- 多媒體地址,如果地址是twitter,發(fā)布版本會有通知
spec.social_media_url = 'https://twitter.com/cocoapods'
spec.social_media_url = 'https://groups.google.com/forum/#!forum/cocoapods'
- 許可,一般MIT,默認與spec文件在同一目錄下
spec.license = 'MIT'
- 指定許可文件
spec.license = { :type => 'MIT', :file => 'MIT-LICENSE.txt' }
指定許可文件的內(nèi)容
spec.license = { :type => 'MIT', :text => <<-LICENSE
Copyright 2012
Permission is granted to...
LICENSE
}
- 項目主頁
spec.homepage = 'http://www.example.com'
- 項目git地址,tag值與spec.verison版本一致
spec.source = { :git => 'https://github.com/AFNetworking/AFNetworking.git',
:tag => spec.version.to_s }
項目git地址,tag值以v開頭,支持子模塊(子模塊是git的子模塊)
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' }
項目壓縮包地址
spec.source = { :http => 'http://dev.wechatapp.com/download/sdk/WeChat_SDK_iOS_en.zip' }
指定壓縮包地址,并校驗hash值,支持sha1 和 sha256
spec.source = { :http => 'http://dev.wechatapp.com/download/sdk/WeChat_SDK_iOS_en.zip',
:sha1 => '7e21857fe11a511f472cfd7cfa2d979bd7ab7d96' }
指定為本地地址
podspec :path => '/Documents/PrettyKit/PrettyKit.podspec'
- 簡介
spec.summary = 'Computes the meaning of life.'
- 詳細描述
spec.description = <<-DESC
這里寫描述內(nèi)容
DESC
- 單個截圖
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' ]
- 文檔說明
spec.documentation_url = 'http://www.example.com/docs.html'
- prepare_command,在pod文件下載完畢之后,執(zhí)行的命令,原文如下
A bash script that will be executed after the Pod is downloaded. This command can be used to create, delete and modify any file downloaded and will be ran before any paths for other file attributes of the specification are collected.
This command is executed before the Pod is cleaned and before the Pods project is created. The working directory is the root of the Pod.
If the pod is installed with the :path option this command will not be executed.
單個命令
spec.prepare_command = 'ruby build_files.rb'
多條命令
spec.prepare_command = <<-CMD
sed -i 's/MyNameSpacedHeader/Header/g' ./**/*.h
sed -i 's/MyNameOtherSpacedHeader/OtherHeader/g' ./**/*.h
CMD
- 是否過期
spec.deprecated = true
- 支持的平臺,如果不寫默認支持所有平臺
spec.platform = :ios //僅支持ios
支持多個平臺
spec.ios.deployment_target = '6.0'
spec.osx.deployment_target = '10.8'
- 依賴的第三方
spec.dependency 'AFNetworking', '~> 1.0'
指定某個平臺的依賴
spec.ios.dependency 'MBProgressHUD', '~> 0.5'
- 是否是ARC,默認true,如果不是,會自動添加
-fno-objc-arc
compiler flag
spec.requires_arc = true
部分是ARC
spec.requires_arc = false
spec.requires_arc = 'Classes/Arc' //該文件夾下是ARC,其它非ARC
spec.requires_arc = ['Classes/*ARC.m', 'Classes/ARC.mm']
- 依賴的系統(tǒng)的框架
spec.ios.framework = 'CFNetwork'
多個framework,用逗號分開
spec.frameworks = 'QuartzCore', 'CoreData'
- weak_frameworks
如果在高版本的OS中調(diào)用新增的功能,并且在低版本的OS中依然能夠運行,那么就要用到weak_frameworks.如果引用的某些類或者接口在低版本中并不支持置蜀,對于不支持的接口奈搜,可以在運行的時候判斷,這樣程序不會出錯盯荤,如果不weak引用馋吗,程序在低版本下啟動的時候就會崩潰掉
spec.weak_framework = 'MessageUI'
- libraries 比如libz,sqlite3.0等,多個用逗號分開
spec.libraries = 'xml2', 'z' //z表示libz.tdb,后綴不需要,lib開頭的省略lib
- compiler_flags
spec.compiler_flags = '-DOS_OBJECT_USE_OBJC=0', '-Wno-format'
- prefix_header_contents 類似于pch,文件,多個用逗號隔開
spec.prefix_header_contents = '#import <UIKit/UIKit.h>', '#import <Foundation/Foundation.h>'
也可以這樣寫:
s.prefix_header_contents = <<-EOS
#ifdef __OBJC__
#import "SGExtension.h" //SGExtension包含了所有頭文件
#endif
EOS
end
- 指定pch文件
spec.prefix_header_file = 'iphone/include/prefix.pch'
- 源文件
spec.source_files = 'Classes/**/*.{h,m}'
spec.source_files = 'Classes/**/*.{h,m}', 'More_Classes/**/*.{h,m}'
- 文件匹配
-
*
匹配所有文件 -
c*
匹配以名字C開頭的文件 -
*c
匹配以名字c結尾的文件 -
*c*
匹配所有名字包含c的文件 -
**
文件夾以及遞歸子文件夾 -
?
任意一個字符(注意是一個字符) -
[set]
匹配多個字符,支持取反 -
{p,q}
匹配名字包括p 或者 q的文件
-
例子:
"JSONKit.?" #=> ["JSONKit.h", "JSONKit.m"] //JSONKit.字符
"*.[a-z][a-z]" #=> ["CHANGELOG.md", "README.md"]//.兩個a-z的字母
"*.[^m]*" #=> ["JSONKit.h"] //.不是m的字符
"*.{h,m}" #=> ["JSONKit.h", "JSONKit.m"] //包含.h或者.m
"*" #=> ["CHANGELOG.md", "JSONKit.h", "JSONKit.m", "README.md"]//所有文件
- 公有頭文件
spec.public_header_files = 'Headers/Public/*.h'
- 私有頭文件
spec.private_header_files = 'Headers/Private/*.h'
- 自己的或者第三方framework,比qqSDK的TencentOpenAPI.framework
spec.vendored_frameworks = 'MyFramework.framework','TheirFramework.framework'
- 自己的或者第三方.a文件,比如微信SDK的.a文件
spec.vendored_libraries = 'libProj4.a', 'libJavaScriptCore.a'
- 資源文件,比如圖片
spec.ios.resource_bundle = { 'MapBox' => 'MapView/Map/Resources/*.png' }
多個路徑
spec.resource_bundles = {
'MapBox' => ['MapView/Map/Resources/*.png'],
'OtherResources' => ['MapView/Map/OtherResources/*.png']
}
這種方式資源文件會被以bundle的形式加入到項目中去,官方建議使用的方式,主要是防止與用戶的命名方式?jīng)_突
- 資源文件另一種方式,這種比較常見
spec.resource = 'Resources/HockeySDK.bundle'
spec.resources = ['Images/*.png', 'Sounds/*']