制作pod时最重要的文件是spec文件,在这个文件中需要按照规则定义pod属性,不同属性意义不同.
cocoapods官网上有详细介绍
spec文件创建
1.直接创建xxx.podspec文件
2.在控制台通过 pod spec create xxx 命令创建
spec属性字段
必要字段:
- name:pod的名称
spec.name = 'AFNetworking'
- version:版本号
版本号应遵循的规则--点击跳转
spec.version = '0.0.1'
- authors:所有者的姓名、邮箱
spec.author = 'Darth Vader'
spec.authors = 'Darth Vader', 'Wookiee'
spec.authors = { 'Darth Vader' => '[email protected]',
'Wookiee' => '[email protected]' }
- license:许可
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主页的URL
spec.homepage = 'http://www.example.com'
-
source:资源位置,即库被检索的位置
支持的关键词为:
最常用的git:tag类型:
spec.source = { :git => 'https://github.com/AFNetworking/AFNetworking.git',
:tag => spec.version.to_s }
支持特定版本子模块
spec.source = { :git => 'https://github.com/typhoon-framework/Typhoon.git',
:tag => "v#{spec.version}", :submodules => true }
svn:tag
spec.source = { :svn => 'http://svn.code.sf.net/p/polyclipping/code', :tag => '4.8.8' }
这个不清楚
spec.source = { :hg => 'https://bitbucket.org/dcutting/hyperbek', :revision => "#{s.version}" }
下载代码的压缩包,压缩格式支持zip、tgz、bz2、txz和tar
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' }
- summary:pod简短描述
spec.summary = 'Computes the meaning of life.'
非必要字段:
root specification
- swift_versions:指定swift版本
spec.swift_versions = ['3.0']
spec.swift_versions = ['3.0', '4.0', '4.2']
spec.swift_version = '3.0'
spec.swift_version = '3.0', '4.0'
- cocoapods_version:CocoaPods版本
spec.cocoapods_version = '>= 0.36'
- social_media_url:社交联系url
spec.social_media_url = 'https://twitter.com/cocoapods'
- description:详细描述
spec.description = <<-DESC
Computes the meaning of life.
Features:
1. Is self aware
...
42. Likes candies.
DESC
- screenshots:显示pod的图像的URL列表。适用于面向用户界面的库
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' ]
- prepare_command:将在pod下载后执行的bash脚本
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
- static_framework:当使用use_frameworks!,指定pod库为静态库
spec.static_framework = true
- deprecated:库是否已被弃用
spec.deprecated = true
- deprecated_in_favor_of:库名已被弃用
spec.deprecated_in_favor_of = 'NewMoreAwesomePod'
Platform
- platform:支持此pod的平台。不填表示pod在所有平台上都受支持。当支持多个平台时,使用deployment_target定义
spec.platform = :osx, '10.8'
spec.platform = :ios
spec.platform = :osx
- deployment_target:允许指定支持此pod的多个平台-为每个平台指定不同的部署目标。
spec.ios.deployment_target = '6.0'
spec.osx.deployment_target = '10.8'
Build setting
- dependency:当前pod所依赖的其他pod库,依赖项可以指定版本号,建议使用 ~> 来指定版本号,因为这种方式不受太多限制,达到很好的版本控制效果,例如,~>1.0.1相当于>= 1.0.1且<1.1。同样,~>1.0将匹配1.0、1.0.1、1.1,但不会升级到2.0
spec.dependency 'AFNetworking', '~> 1.0'
spec.dependency 'RestKit/CoreData', '~> 0.20.0'
spec.ios.dependency 'MBProgressHUD', '~> 0.5'
- requires_arc:允许你指定哪些源使用arc,不使用arc的文件会有 -fno-objc-arc 编译器标志
spec.requires_arc = true
spec.requires_arc = false
spec.requires_arc = 'Classes/Arc'
spec.requires_arc = ['Classes/*ARC.m', 'Classes/ARC.mm']
- frameworks:指定导入的系统framework
spec.ios.framework = 'CFNetwork'
spec.frameworks = 'QuartzCore', 'CoreData'
- weak_frameworks:弱链接库,比如说一个项目同时兼容iOS6和iOS7,但某一个framework只在iOS7上有,这时候如果用强链接,那么在iOS7上运行就会crash,使用weak_frameworks可以避免这种情况。
spec.weak_framework = 'Twitter'
spec.weak_frameworks = 'Twitter', 'SafariServices'
- libraries:需要导入的系统静态库
spec.ios.library = 'xml2'
spec.libraries = 'xml2', 'z'
- compiler_flags:编译器参数
spec.compiler_flags = '-DOS_OBJECT_USE_OBJC=0', '-Wno-format'
- pod_target_xcconfig:修改pod本身target的配置项
s.pod_target_xcconfig = { 'ENABLE_BITCODE' => 'false' }
- user_target_xcconfig: 修改依赖该pod的主项目的配置项,不建议使用
s.user_target_xcconfig = { 'ENABLE_BITCODE' => 'false' }
- prefix_header_contents:类似于pch,文件,多个用逗号隔开
spec.prefix_header_contents = '#import '
spec.prefix_header_contents = '#import ', '#import '
- prefix_header_file:指定pch文件
spec.prefix_header_file = 'iphone/include/prefix.pch'
spec.prefix_header_file = false
- script_phases:允许定义script phase语句在pod编译时执行
spec.script_phase = { :name => 'Hello World', :script => 'echo "Hello World"' }
spec.script_phase = { :name => 'Hello World', :script => 'echo "Hello World"', :execution_position => :before_compile }
spec.script_phase = { :name => 'Hello World', :script => 'puts "Hello World"', :shell_path => '/usr/bin/ruby' }
spec.script_phase = { :name => 'Hello World', :script => 'echo "Hello World"',
:input_files => ['/path/to/input_file.txt'], :output_files => ['/path/to/output_file.txt']
}
spec.script_phase = { :name => 'Hello World', :script => 'echo "Hello World"',
:input_file_lists => ['/path/to/input_files.xcfilelist'], :output_file_lists => ['/path/to/output_files.xcfilelist']
}
spec.script_phases = [
{ :name => 'Hello World', :script => 'echo "Hello World"' },
{ :name => 'Hello Ruby World', :script => 'puts "Hello World"', :shell_path => '/usr/bin/ruby' },
]
File patterns
文件匹配规则
通配符 *
- *匹配所有文件
- c*匹配以c开头的文件
- *c匹配以c结尾的文件
- c匹配文件名包含c的文件(包括以c开头结尾的文件)
通配符 **
- 递归匹配目录
通配符?
- 匹配任意的一个字符
通配符[set]
- 匹配在集合中的任意一个字符
通配符{p,q}
- 匹配{}中的任意-个字符
通配符\
- 转义符号
例如:
"JSONKit.?" #=> ["JSONKit.h", "JSONKit.m"]
"*.[a-z][a-z]" #=> ["CHANGELOG.md", "README.md"]
"*.[^m]*" #=> ["JSONKit.h"]
"*.{h,m}" #=> ["JSONKit.h", "JSONKit.m"]
"*" #=> ["CHANGELOG.md", "JSONKit.h", "JSONKit.m", "README.md"]
- source_files:源文件路径,需要配置,指明源文件路径
spec.source_files = 'Classes/**/*.{h,m}'
spec.source_files = 'Classes/**/*.{h,m}', 'More_Classes/**/*.{h,m}'
- public_header_files:当需要明确指出头文件时必须指明,例如:当source为:http模式配置的压缩包形式,指明头文件所在路径,如.a压缩包库,解压后的头文件目录;还有当配置了vendored_libraries项,需要明确指出头文件路径
spec.public_header_files = 'Headers/Public/*.h'
- private_header_files:私有头文件路径,与public_header_files相对,不会暴漏给用户target的头文件
spec.private_header_files = 'Headers/Private/*.h'
- vendored_frameworks:pod附带的framework路径,例如如果将pod制作成一个framework上传到git上面,如果想pod下来这个framework则必须指定这个字段
spec.ios.vendored_frameworks = 'Frameworks/MyFramework.framework'
spec.vendored_frameworks = 'MyFramework.framework', 'TheirFramework.framework'
- vendored_libraries:pod附带的.a路径
spec.ios.vendored_library = 'Libraries/libProj4.a'
spec.vendored_libraries = 'libProj4.a', 'libJavaScriptCore.a'
- resource_bundles:资源配置
spec.ios.resource_bundle = { 'MapBox' => 'MapView/Map/Resources/*.png' }
spec.resource_bundles = {
'MapBox' => ['MapView/Map/Resources/*.png'],
'MapBoxOtherResources' => ['MapView/Map/OtherResources/*.png']
}
- resources:资源配置
spec.resource = 'Resources/HockeySDK.bundle'
spec.resources = ['Images/*.png', 'Sounds/*']
- exclude_files:排除掉某些文件,使其不被匹配到
spec.ios.exclude_files = 'Classes/osx'
spec.exclude_files = 'Classes/**/unused.{h,m}'
- preserve_paths:指定下载后不应删除的文件,默认情况下,cocoapods会删除所有与其他文件模式不匹配的文件
spec.preserve_path = 'IMPORTANT.txt'
spec.preserve_paths = 'Frameworks/*.framework'
- module_map:当这个pod集成为框架时应该使用的模块映射文件。默认情况下,cocoapods根据规范中的公共头创建模块映射文件,主要是给swift使用
spec.module_map = 'source/module.modulemap'