cocoapods系列教程---spec文件

cocoapods系列教程---安装与使用
cocoapods系列教程---Podfile文件
cocoapods系列教程---Podfile.lock文件 和 Spec Repo
cocoapods系列教程---spec文件
cocoapods系列教程---原理篇
cocoapods系列教程---让自己的开源框架支持cocoapods
cocoapods系列教程---模块化设计
cocoapods系列教程---创建私有pods

下面介绍spec文件的详细设置.基本上是根据官网翻译过来的,有什么不对还望指点

  • name
spec.name = 'AFNetworking'

  • 版本
spec.version = '0.0.1'

  • 支持的cocoapods的版本
spec.cocoapods_version = '>= 0.36'

  • 配置信息,根据个人需要填写
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' => '[email protected]',
                 'Wookiee'     => '[email protected]' }

  • 多媒体地址,如果地址是twitter,发布版本会有通知
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' }

指定许可文件的内容

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

                   这里写描述内容
                    
                   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文件下载完毕之后,执行的命令,原文如下
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']

  • 依赖的系统的框架
spec.ios.framework = 'CFNetwork'

多个framework,用逗号分开

spec.frameworks = 'QuartzCore', 'CoreData'

  • weak_frameworks
    如果在高版本的OS中调用新增的功能,并且在低版本的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 ', '#import '

也可以这样写:

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的形式加入到项目中去,官方建议使用的方式,主要是防止与用户的命名方式冲突

  • 资源文件另一种方式,这种比较常见
spec.resource = 'Resources/HockeySDK.bundle'
spec.resources = ['Images/*.png', 'Sounds/*']

你可能感兴趣的:(cocoapods系列教程---spec文件)