详情请参考:Cocoapods官方文档 - Podspec Syntax Reference
1.创建本地Pods库
使用以下命令 创建pods库模板:
pod lib create UploadSDK
该命令需要输入一些参数,可按照如下依次输入:
完成后生成如下模板(已删除注释):
UploadSDK.podspec
Pod::Spec.new do |s|
s.name = 'UploadSDK'
s.version = '0.1.0'
s.summary = 'A short description of UploadSDK.'
s.description = <<-DESC
TODO: Add long description of the pod here.
DESC
s.homepage = 'https://github.com/sammylan/UploadSDK'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'sammylan' => 'sammylan234@gmail.com' }
s.source = { :git => 'https://github.com/sammylan/UploadSDK.git', :tag => s.version.to_s }
s.ios.deployment_target = '8.0'
s.source = { :git => 'https://github.com/sammylan/UploadSDK.git', :tag => s.version.to_s }
s.source_files = 'UploadSDK/Classes/**/*'
end
需要修改的字段
- s.homepage
- s.source
修改后结果如下
Pod::Spec.new do |s|
s.name = 'UploadSDK'
s.version = '0.1.0'
s.summary = 'A short description of UploadSDK.'
s.description = <<-DESC
TODO: Add long description of the pod here.
DESC
s.homepage = 'https://git.code.oa.com/wesing/WSUploadSDK'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'sammylan' => 'sammylan234@gmail.com' }
s.source = { :git => 'http://git.code.oa.com/wesing/WSUploadSDK.git', :tag => s.version.to_s }
s.ios.deployment_target = '8.0'
s.source_files = 'UploadSDK/Classes/**/*'
s.xcconfig = {
'ENABLE_STRICT_OBJC_MSGSEND' => 'NO'
}
end
因为UploadSDK总用到objc_msgSend
,会提示如下编译错误
error: too many arguments to function call, expected 0, have 2
[descriptionString insertString:[NSString stringWithFormat:formatString, property_getName(properties[i]), objc_msgSend(self, sel)] atIndex:0];
~~~~~~~~~~~~ ^~~~~~~~~
需要将Enable Strict Checking of objc_msgSend Calls
设为NO解决该问题,如下
要用pod的方法解决该问题,有两种方法
-
方法1:在
Podfile
的post_install
添加config.build_settings['ENABLE_STRICT_OBJC_MSGSEND'] = 'NO'
解决:
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
config.build_settings['ENABLE_STRICT_OBJC_MSGSEND'] = 'NO'
end
end
end
-
方法2:在
.podspec
总添加'ENABLE_STRICT_OBJC_MSGSEND' => 'NO'
解决:
s.xcconfig = {
'ENABLE_STRICT_OBJC_MSGSEND' => 'NO'
}
以下是修改后的UploadSDK.podspec
文件:
Pod::Spec.new do |s|
s.name = 'UploadSDK'
s.version = '0.1.0'
s.summary = 'A short description of UploadSDK.'
s.description = <<-DESC
TODO: Add long description of the pod here.
DESC
s.homepage = 'https://git.code.oa.com/wesing/WSUploadSDK'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'sammylan' => 'sammylan234@gmail.com' }
s.source = { :git => 'http://git.code.oa.com/wesing/WSUploadSDK.git', :tag => s.version.to_s }
s.ios.deployment_target = '8.0'
s.source_files = 'UploadSDK/Classes/**/*'
s.xcconfig = {
'ENABLE_STRICT_OBJC_MSGSEND' => 'NO'
}
end
如下引入本地pods库:
use_frameworks!
platform :ios, '8.0'
target 'UploadSDK_Example' do
pod 'UploadSDK', :path => '../'
target 'UploadSDK_Tests' do
inherit! :search_paths
end
end
引入本地库后,会有一个Development Pods
分组专门存放本地库,如下
注意:一个库里面如果同时提供二进制库和源码库,那么主工程使用二进制库的时候会提示找不到头文件,这时候需要给二进制库提供FRAMEWORK_SEARCH_PATHS
编译选项,如下:
subspec.xcconfig = {
'OTHER_LDFLAGS' => '-ObjC',
'FRAMEWORK_SEARCH_PATHS' => "\"${PODS_ROOT}/../QQKSong/Framework/WnsSDK\""
}
2.创建远程Pods私有库
- 创建一个创库,用于存放podspec: git@git.code.oa.com:karaoke-cocoapods/Specs.git
- 执行以下命令,创建本地仓库
pod repo add karaoke-cocoapods git@git.code.oa.com:karaoke-cocoapods/Specs.git
- 将库上传到远程仓库
pod repo push oa-karaoke-cocoapods-specs WSCommonLibs.podspec --sources='https://git.code.oa.com/karaoke-cocoapods/Specs.git','https://github.com/CocoaPods/Specs.git' --use-libraries --skip-import-validation --allow-warnings --verbose
附录:添加编译选项
s.xcconfig = {
'ENABLE_STRICT_OBJC_MSGSEND' => 'NO'
}
删除cocoapods
/Library/Ruby/Gems/2.3.0/gems/
- 使用
gem list cocoa*
列出cocoapods相关组件 - 使用
sudo gem uninstal
相关组件
常用命令列表
-
pod lib create
NAME : 创建模板, iOS → ObjC → Yes → None → No → WS -
pod lib lint
--allow-warnings --sources=http://git.code.oa.com/karaoke-cocoapods/Specs.git,master
CocoaPods缓存
缓存文件可能影响pod install的安装结果,遇到非预期的执行结果时,可以考虑检查或者清除缓存重新安装。
- repo缓存位置:~/.cocoapods/repos/
- Pods缓存位置:~/资源库/Caches/CocoaPods/Pods/
Podfile添加编译选项
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['ENABLE_BITCODE'] = 'NO'
if target.name != 'AA' and target.name != 'AA'
if config.name == 'Debug'
config.build_settings['OTHER_CFLAGS'] ||=['(inherited)','-DNS_BLOCK_ASSERTIONS=1','-DNDEBUG']
end
end
end
end
end
网友评论