CocoaPods是iOS开发、macOS开发中的包依赖管理工具,使用ruby编写
安装
使用ruby的gem命令安装CocoaPods
// 查看ruby版本号
ruby --version
// 查看gem版本号
gem --version
// gem 版本号过低,回导致CocoaPods安装失败,更新gem
sudo gem update --system
// 查看gem 使用的源
gem source -l
// 切换gem 使用的源
gem sources --remove https://rubygems.org/
gem sources -a https://ruby.taobao.org/
// 安装cocoapods
sudo gem install cocoapods
// cocoapods 初始化
pod setup
// 查看pod 版本
pod --version
使用
// 在.xcodeproj的同级目录下面新建一个Podfile
touch Podfile
// 编辑Podfile
platform :ios, '11.0'
target 'TestCocoaPods' do
pod 'SDWebImage', '~> 4.3.2'
end
// 安装依赖
pod install
// 更新依赖
pod update
开源库支持Cocapods
新建podspec文件
pod spec create IDbg
编辑podspec 文件
Public headers 设置:public_header_files
链接framework设置:vendored_frameworks
链接资源文件设置:resources
编译设置:s.xcconfig = {‘OTHER_LDFLAGS’ => ‘-ObjC -lz -lsqlite3 -lc -lresolv -lbz2 -liconv’,”HEADER_SEARCH_PATHS” => ‘ “${PODS_ROOT}/../../sdk/third_party/IDbg/iOS/IDbg.framework/Headers”‘}
Pod::Spec.new do |spec|
spec.name = "IDbg"
spec.version = "1.0.3"
spec.summary = "IDbg client"
spec.description = "debug tools"
spec.homepage = "https://github.com/oc-sample/IDbg-sdk"
spec.license = { :type => "MIT", :file => "LICENSE" }
spec.author = { "mjsecurity" => "mjsecurity@126.com" }
spec.ios.deployment_target = "11.0"
spec.source = { :git => "https://github.com/oc-sample/IDbg-sdk.git", :tag => "#{spec.version}" }
spec.source_files = "IDbg.framework/Headers", "*.{h,m}"
spec.vendored_frameworks = 'IDbg.framework'
spec.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
spec.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
end
分支新建tag,并推送到远程仓库
git tag 1.0.3
git push --tags
验证podspec文件
pod spec lint IDbg.podspec
注册Cocoapods
pod trunk register mjsecurity@126.com '昵称名' --description='描述'
提交至CocoaPods
pod trunk push IDbg.podspec
也可以不推送Cocoapods,而以私有库的方式使用,用法如下
pod 'IDbg',git=>"https://XXX.git"