目錄
profile相關(guān)參數(shù)
1. 依賴相關(guān)的指令
-
pod : 聲明一個(gè)依賴庫
-
版本
//使用最新的版本 pod 'SSZipArchive' //指定使用某個(gè)版本 pod 'Objection', '0.9' //0.1.2與0.2版本之間的最新版本 pod 'Objection', '~> 0.1.2'
-
Build配置
//只有在debug模式下才使用PonyDebugger庫 pod 'PonyDebugger', :configuration => 'Debug'
-
Subspecs 配置
Subspecs 配置简烤, 只使用pod中某一個(gè)或者某一些子pod 庫(需要pod庫支持) //使用QueryKit下的Attribute庫: pod 'QueryKit/Attribute' //使用QueryKit下的Attribute庫和QuerySet庫: pod 'QueryKit', :subspecs => ['Attribute', 'QuerySet']
-
本地pod庫(cocoapod會在指定的文件夾下找podspec先巴,所以當(dāng)前文件夾下一定要有podspec文件)
pod 'AFNetworking', :path => '~/Documents/AFNetworking'
-
設(shè)置pod庫
//使用master分支 pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git' //使用指定分支 pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :branch => 'dev' //使用指定tag pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :tag => '0.7.0' //使用某一次commit pod 'AFNetworking', :git => 'https://github.com/gowalla/AFNetworking.git', :commit => '082f8319af
-
設(shè)置podSpec的來源
-
pod 'JSONKit', :podspec => 'https://example.com/JSONKit.podspec'
-
Target : 與project中的target保持一致,默認(rèn)target會繼承外面的依賴庫
簡單應(yīng)用:
target 'ZipApp' do
pod 'SSZipArchive'
end
繼承別的target的依賴庫
target 'ZipApp' do
pod 'SSZipArchive'
target 'ZipAppTests' do
inherit! :search_paths
pod 'Nimble'
end
end
繼承多個(gè)target的依賴庫(ShowsTests 同時(shí)有ShowsApp和)
target 'ShowsApp' do
pod 'ShowsKit'
# Has its own copy of ShowsKit + ShowTVAuth
target 'ShowsTV' do
pod 'ShowTVAuth'
end
target 'ShowsTests' do
inherit! :search_paths
pod 'Specta'
pod 'Expecta'
end
end
-
抽象Target : 方便其他target繼承(這個(gè)抽象的target是不存在的)
abstract_target 'Networking' do
pod 'AlamoFire'
target 'Networking App 1'
target 'Networking App 2'
end
# Note: There are no targets called "Shows" in any of this workspace's Xcode projects
abstract_target 'Shows' do
pod 'ShowsKit'
# The target ShowsiOS has its own copy of ShowsKit (inherited) + ShowWebAuth (added here)
target 'ShowsiOS' do
pod 'ShowWebAuth'
end
# The target ShowsTV has its own copy of ShowsKit (inherited) + ShowTVAuth (added here)
target 'ShowsTV' do
pod 'ShowTVAuth'
end
# Our tests target has its own copy of
# our testing frameworks, and has access
# to ShowsKit as well because it is
# a child of the abstract target 'Shows'
target 'ShowsTests' do
inherit! :search_paths
pod 'Specta'
pod 'Expecta'
end
end
-
inherit!:給當(dāng)前target設(shè)置集成模式
參數(shù)有
:complete : 全部繼承父target
:none :全部不繼承
:search_paths :只繼承父target的searchPaths
例如:
target 'App' do
target 'AppTests' do
inherit! :search_paths
end
end
2. Target配置
platform: 兩個(gè)參數(shù)蒲列。一個(gè)是name, 一個(gè)是target
name屬性
osx for OS X, :ios for iOS, :tvos for tvOS, or :watchos for watchOS.
target:版本
例如:
platform :ios, '4.0'
platform :ios
inhibit_all_warnings : 忽略所有庫中的警告购对,也可以指定某一個(gè)具體庫的警告。例如:
//全部忽略
platform :ios, '8.0'
inhibit_all_warnings!
source 'https://github.com/CocoaPods/Specs.git'
target 'TestPod' do
pod 'SummerOCProjectFrame', '~> 0.0'
end
//某一個(gè)忽略
pod 'SummerOCProjectFrame', '~> 0.0', :inhibit_warnings => true
3. Source : 可以指定CocoaPods Master Repository,也可以自定義的Repository。例如:
source 'https://github.com/artsy/Specs.git'
source 'https://github.com/CocoaPods/Specs.git'
4. Hooks: 提供在初始化過程中接口
plugin:插件镀钓。描述在初始化時(shí)候使用的插件。例如:
plugin 'cocoapods-keys', :keyring => 'Eidolon'
plugin 'slather'
pre_install:在pod下載完初始化前可以通過它做邏輯處理镀迂。例如:
pre_install do |installer|
# Do something fancy!
end
post_install:在形成project后寫入本地前可以通過它做邏輯處理掸宛。比如設(shè)置target的build setting, 代碼如下:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['GCC_ENABLE_OBJC_GC'] = 'supported'
end
end
end
5. def name end。 如果project依賴的庫很多招拙,比如有自己開發(fā)的庫,有第三方的庫措译,可以對這些庫進(jìn)行分類别凤。例如:
def myPods
pod xxx
pod xxx1
pod xxx2
end
def thirdPods
pod yyy
pod yyy1
pod yyy2
end
target 'xxx' do
myPods
thirdPods
end
參考:https://guides.cocoapods.org/syntax/podfile.html#podfile
podspec相關(guān)參數(shù)
-
一些參數(shù):
- prefix_header_file : 給pod庫設(shè)置pch文件
- dependency : 設(shè)置依賴庫
- weak_framework :兼容高低版本api的問題,類似于主工程中frame里面的option屬性
- libraries领虹, framework
- compiler_flags规哪,例如
spec.compiler_flags = '-DOS_OBJECT_USE_OBJC=0', '-Wno-format'
- 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>'
- source_files, public_header_files(不寫默認(rèn)是所有.h文件)塌衰,private_header_files诉稍。source支持如下幾種源:
//git源 :git => :tag, :branch, :commit, :submodules spec.source = { :git => 'https://github.com/AFNetworking/AFNetworking.git', :tag => spec.version.to_s } //:svn => :folder, :tag, :revision spec.source = { :svn => 'http://svn.code.sf.net/p/polyclipping/code', :tag => '4.8.8' } //:hg => :revision spec.source = { :hg => 'https://bitbucket.org/dcutting/hyperbek', :revision => "#{s.version}" } //:http => :flatten, :type, :sha256, :sha1 spec.source = { :http => 'http://dev.wechatapp.com/download/sdk/WeChat_SDK_iOS_en.zip' } //:path
- vendored_frameworks: pod庫的frame
- vendored_libraries: 第三方.a文件
spec.vendored_libraries = 'xxx/Classes/ThirdParty/*.{a}'
- resource_bundles,resources
spec.resource_bundles = {
'MapBox' => ['MapView/Map/Resources/*.png'],
'OtherResources' => ['MapView/Map/OtherResources/*.png']
}
spec.resources = ['Images/*.png', 'Sounds/*']
- preserve_path: install 或者 update之后不會更新的文件路徑
spec.preserve_path = 'IMPORTANT.txt'
spec.preserve_paths = 'Frameworks/*.framework'
- exclude_files : 不包含的文件最疆。例如:
spec.exclude_files = 'Classes/**/unused.{h,m}'
- subspec : 子spec杯巨。可以使用spec中所有屬性六荒。比如不同的source_file, 不同的dependencies毅臊。例如:
//不同的source_file
subspec 'Twitter' do |sp|
sp.source_files = 'Classes/Twitter'
end
subspec 'Pinboard' do |sp|
sp.source_files = 'Classes/Pinboard'
end
Pod::Spec.new do |s|
s.name = 'RestKit'
//不同的dependencies
s.subspec 'Core' do |cs|
cs.dependency 'RestKit/ObjectMapping'
cs.dependency 'RestKit/Network'
cs.dependency 'RestKit/CoreData'
end
s.subspec 'ObjectMapping' do |os|
end
end
參考:https://guides.cocoapods.org/syntax/podspec.html
清除pod緩存
第一步:
pod cache list //查看看緩存
pod cache clean --all //清除緩存
如果還不行您朽,就執(zhí)行下面的代碼:
rm ~/Library/Caches/CocoaPods/search_index.json;
pod sutup