【cocoapods】 github 绑定 cocoapods使用

前言

ios的包管理库 :https://cocoapods.org/ 类似于maven服务(类似的android的 开源库的使用参考这里
ios开发项目中可以方便的在Podfile中进行如下引用(Podfile 默认都懂)

pod 'AFNetworking', '~> 3.0'

三个问题:

  • AFNetworking 是如何引入系统的
  • 3.0这个版本怎么管理的,更换版本的时候是通过什么机制能有效引入的
  • 如果开源方 删除了源代码,是不是就不能用了

带着问题进入今天的主题,使用github作为源代码仓库,使用cocoapods作为包版本管理库的操作步骤,通过此文我们可以快速的在开源的世界里作出自己的一份贡献并且让人方便引入(默认大家都知道git 的基础使用,如果有需要笔者会写一些一些关于git的使用教程)

步骤

git 项目操作

git clone https://github.com/mobidevos/IAEngine.git
cd IAEngine

创建podspec文件

mkdir IAEngine.podspec

修改podspec文件

Pod::Spec.new do |s|
  s.name         = "IAEngine" 
  s.version      = "0.0.1"
  s.summary      = "IAEngine is a high level ios engine"
  s.homepage     = "https://github.com/mobidevos/IAEngine"
  s.license      = "MIT"
  s.author       = {
                    "zhujohnle" => "[email protected]"
 }
  s.source        = { :git => "https://github.com/mobidevos/IAEngine.git", :tag => s.version.to_s }
  s.source_files  = "IAEngine/*.{h,m}"
  s.requires_arc  = true

  s.private_header_files = "IAEngine/IAEngine.h"

  s.ios.deployment_target = "7.0"
  s.osx.deployment_target = "10.9"
  s.watchos.deployment_target = "2.0"
  s.tvos.deployment_target = "9.0"
  s.dependency "AFNetworking", "~> 3.0"
end

将本地文件push到远程git

git add .
git commit -m "添加podspec 文件"

添加tag值并推送

git tag -m "first release" "0.0.1"
git push --tags

cocoapods操作

本地验证

pod lib lint IAEngine.podspec --allow-warnings

TimeTool passed validation. 提示的时候即为成功,否则按照提示进行对应的修改

注册trunk

pod trunk register [email protected] 'mobidevos' --description='regist trunk'
(邮箱和用户名为github的)

会提示到邮箱里进行验证,收到邮件里面有地址访问即可

验证上传的spec文件是否有效

pod spec lint IAEngie.podspec --allow-warnings

将仓库推送到cocoapods上

pod trunk push TimeTool.podspec --allow-warnings

在这里插入图片描述

至此操作结束!

问题总结

0.上传之前建议更新ruby 更新cocopods参考

1.使用pod search TimeTool 搜索不到


进入~/Library/Caches/CocoaPods/
删除search_index.json文件,下次pod search会自动生成

2.保证podspec文件书写正确

#pod的仓库地址
s.source       = { :git => "https://github.com/mobidevos/IAEngine.git", :tag => "#{s.version}" }
#如需依赖其他库,添加s.dependency
s.dependency 'MBProgressHUD', '~> 1.1.0'
s.dependency 'MJRefresh'

猜你喜欢

转载自blog.csdn.net/zhujohnle/article/details/85101058