iOS高级开发iOS组件化快速入门iOS

cocoapods系列教程---spec文件

2016-09-18  本文已影响4498人  youngyunxing

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

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

spec.name = 'AFNetworking'

spec.version = '0.0.1'

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' => 'darthvader@darkside.com',
                 'Wookiee'     => 'wookiee@aggrrttaaggrrt.com' }

spec.social_media_url = 'https://twitter.com/cocoapods'

spec.social_media_url = 'https://groups.google.com/forum/#!forum/cocoapods'

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'

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'

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'

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'

spec.weak_framework = 'MessageUI'

spec.libraries = 'xml2', 'z'  //z表示libz.tdb,后缀不需要,lib开头的省略lib

spec.compiler_flags = '-DOS_OBJECT_USE_OBJC=0', '-Wno-format'

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

spec.prefix_header_file = 'iphone/include/prefix.pch'

spec.source_files = 'Classes/**/*.{h,m}'
spec.source_files = 'Classes/**/*.{h,m}', 'More_Classes/**/*.{h,m}'

例子:

"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'

spec.vendored_frameworks = 'MyFramework.framework','TheirFramework.framework'

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/*']

上一篇下一篇

猜你喜欢

热点阅读