前言
一般而言,大多数开源框架都是托管在GitHub上,然而光是托管上去,并不能直接使用CocoaPods提供版本支持,所以需要开发人员通过一系列操作来提供支持。
正文
假设已有一个开源框架在GitHub上,名称姑且称之为HelloWorldFramework,首先在将代码clone到本地:
git clone git@github.com:fangzhenxing/HellloWorldFramework.git
然后在GitHub上创建一个release版本:
然后在工程主目录下使用命令生成specs文件:
pod spec create HellloWorldFramework
specs文件会自动生成在工程目录中,然后可以根据需要进行配置:
Pod::Spec.new do |spec|
spec.name = "HellloWorldFramework"
spec.version = "1.0.0"
spec.summary = "print 'hello world'."
spec.homepage = "https://github.com/fangzhenxing/HellloWorldFramework"
spec.license = "MIT"
spec.author = { "fangzhenxing" => "17512081435@163.com" }
spec.ios.deployment_target = "8.0"
spec.source = { :git => "https://github.com/fangzhenxing/HellloWorldFramework.git", :tag => "#{spec.version}" }
spec.source_files = "HellloWorldFramework/HellloWorldFramework/*.{h,m}"
spec.requires_arc = true
end
使用命令校验specs文件是否编写有错误:
pod lib lint --allow-warnings --skip-import-validation
如果出现以下内容则表示校验通过:
HellloWorldFramework passed validation.
然后创建一个CocoaPods账号,之后在邮箱验证一下就可以了:
pod trunk register 你的邮箱 '用户名' —description='描述信息'
然后将specs推送到GitHub上:
pod trunk push HellloWorldFramework.podspec --allow-warnings
这样,开源项目对CocoaPods的支持就完成了。
测试
新建一个测试项目HelloWorldTest,编写Podfile文件内容如下:
# Uncomment the next line to define a global platform for your project
platform :ios, '8.0'
target 'HelloWorldTest' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for HelloWorldTest
pod 'HellloWorldFramework'
end
然后使用命令将框架pull到本地:
pod install --repo-update
就大功告成了!
后续
后面将会增加pod多个release版本下如何处理的问题,以及详细解析specs所有配置项的含义和如何去使用,敬请期待......