让你的项目支持Cocoa Pods

让你的项目支持Cocoa Pods,作为第三方库方便的被别人使用:

本案前提
  你已经有一个项目,并且上传到了gitbug上
  项目含有liecnce文件(没有的话,后面校验不会通过)
准备工作一:注册trunk

pod trunk register EMAIL [NAME]

Examples:
$ pod trunk register eloy@example.com `Eloy Durán` --description=`Personal Laptop`
$ pod trunk register eloy@example.com --description=`Work Laptop`
$ pod trunk register eloy@example.com

然后会收到邮件,点击邮件链接确认
准备工作二:为你的项目添加PodSpec
  在当前工作目录中创建一个名为NAME.podspec的PodSpec
  pod spec create [NAME|https://github.com/USER/REPO]

编辑本地生成的NAME.podspec文件 

一个简单的例子:
Pod::Spec.new do |spec|
  spec.name             = 'Reachability'
  spec.version          = '3.1.0'
  spec.license          = { :type => 'BSD' }
  spec.homepage         = 'https://github.com/tonymillion/Reachability'
  spec.authors          = { 'Tony Million' => 'tonymillion@gmail.com' }
  spec.summary          = 'ARC and GCD Compatible Reachability Class for iOS and macOS.'
  spec.source           = { :git => 'https://github.com/tonymillion/Reachability.git', :tag => 'v3.1.0' }
  spec.source_files     = 'Reachability.h,m'
  spec.framework        = 'SystemConfiguration'
  spec.requires_arc     = true
end

校验:
pod spec lint [NAME.podspec|DIRECTORY|http://PATH/NAME.podspec ...]
或 pod lib lint 
或 pod spec lint --allow-warnings --verbose NAME.podspec 显示错误信息和警告
如果有错误就根据提示修改NAME.podspec


确认无误,提交code到git仓库中,并打上tag版本号
创建Spec Repo
pod repo add NAME URL [BRANCH]
如:
pod repo add NAME http://PATH/NAME.podspec

远程代码被拷贝在本地,在 ~/.cocoapods/repos/. 中可以查看
这样我们在一天github上的项目就被指定为Cocoa pods中名为NAME的项目
向Spec Repo提交podspec

#前面是本地Repo名字 后面是podspec名字
pod repo push REPO_NAME SPEC_NAME.podspec
如:
pod repo push myPods somePods.podspec

在项目中使用CocoaPods

touch Podfile

source 'https://github.com/CocoaPods/Specs.git'
source 'https://github.com/Artsy/Specs.git'

platform :ios, '9.0'
inhibit_all_warnings!

target 'MyApp' do
  pod 'GoogleAnalytics', '~> 3.1'

  # Has its own copy of OCMock
  # and has access to GoogleAnalytics via the app
  # that hosts the test target

  target 'MyAppTests' do
    inherit! :search_paths
    pod 'OCMock', '~> 2.0.1'
  end
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    puts target.name
  end
end
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 177,135评论 25 709
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 14,797评论 4 61
  • 吹拂临波怒海天,潮汕奔流坐参禅,跳出五云扫大地,满嘴鸡毛滚如山,抑郁乎!海州天地,何故狂风大作,疾走闪电,枯竹拉朽...
    赛腾烟阅读 3,222评论 4 13
  • 我们活在多荒诞的时代—— 手机没电了,就代表那个人失联了。 1 当手机电量格由绿色变成红色时,你便会开始焦躁不安,...
    张嘉豪sky阅读 3,613评论 3 5
  • 以前:使命,投资,乐趣 现在:责任,无私,独立 我觉得人要想过的辛福,一定要把养孩子这件事从以使命、投资、乐趣为角...
    笔墨侍书阅读 1,724评论 0 0

友情链接更多精彩内容