【iOS】让自己的开源项目支持CocoaPods

测试的时候找个自己封装的方法或UI控件就可以了 这里用我刚封装的Redirect重定向的请求体为例

1, 在github上创建一个Redirect,重要:记得选择开源协议 (MIT)(如果木有GitHub那先百度一下)

679636-20180111173041676-991063603.png

2, 使用 Github Desktop Clone (克隆) Redirect 到电脑桌面 

注: 修改Redirect文件里的东西记得及时更新,如何使用Github Desktop请百度

3, cd到当前目录

1
$ cd Redirect

4, 创建一个podspec文件,命令:

1
$ pod spec create Redirect

5, 编辑 podspec文件,这里是用vim打开的,命令:(当然使用文本编辑器打开也可以)

1
$ vim Redirect.podspec

6, 创建之后会自动生成一个模板,里面会有详细的注释,我们只需要按需要修改这个文件即可,

下边这个是测试的时候我编辑的 (如果需要更更多的配置 可以参考别的开源项目的podspec文件):

(注: 以#开头的是可以删掉滴)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Pod::Spec. new   do   |s|
   s.name         =  "Redirect"
   s.version      =  "0.0.1"
   s.summary      =  "Redirecting Requests."
   s.description  = <  "1139981137@qq.com"   }
   s.platform     = :ios
   s.source       = { :git =>  "https://github.com/ganlinmeng/Redirect.git" , :tag => "0.0.1"   }
   s.source_files  =  "Redirect" "Redirect/**/*.{h,m}"
   s.exclude_files =  "Classes/Exclude"
   s.framework  =  "UIKit"
   # s.frameworks =  "SomeFramework" "AnotherFramework"
   # s.library   =  "iconv"
   # s.libraries =  "iconv" "xml2"
   # ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
   #
   #  If your library depends on compiler flags you can  set   them  in   the xcconfig hash
   #  where they will only apply to your library. If you depend on other Podspecs
   #  you can  include   multiple dependencies to ensure it works.
   # s.requires_arc =  true
   # s.xcconfig = {  "HEADER_SEARCH_PATHS"   =>  "$(SDKROOT)/usr/include/libxml2"   }
   # s.dependency  "JSONKit" "~> 1.4"
end

s.name:名称,pod search 搜索的关键词,注意这里一定要和.podspec的名称一样,否则报错

s.version:版本号

s.ios.deployment_target:支持的pod最低版本

s.summary: 简介

s.homepage:项目主页地址

s.license:许可证

s.author:作者

s.social_media_url:社交网址

s.source:项目的地址

s.source_files:需要包含的源文件

s.resources: 资源文件

s.requires_arc: 是否支持ARC

s.dependency:依赖库,不能依赖未发布的库

s.dependency:依赖库,如有多个可以这样写

(注: 也有这样写: s.license= { :type => "MIT", :file => "LICENSE" }

7, 创建tag,并推送到github,依次执行以下命令:

1
2
3
4
5
$ git add .
$ git commit -m  "0.0.1"
$ git tag  0.0 . 1
$ git push --tags
$ git push origin master

(注: 当执行完 git push --tags  后终端会让你输入GitHub的账号和密码)

Username for 'https://github.com':

Password for 'https://ganlinmeng@github.com': 

8, 验证podspec文件

1
$ pod spec lint Redirect.podspec

如果终端提示 (but you can use `--allow-warnings` to ignore them).

你可以

1
$ pod spec lint Redirect.podspec --allow-warnings
  • 如果验证不通过,会有详细的ERROR和WARING提示,根据提示依次解决,然后回到第7步重新来一遍。

注意:在重新开始之前,我们要删除远程库的tag和本地的tag,命令如下:

1
2
$ git tag -d  1.2                     //删除本地tag
$ git push origin :refs/tags/ 1.2    // 删除远程库tag

如果验证通过会这样显示

679636-20180111173146488-923969896.png

9, 如果是第一次提交,需要先执行这个命令:

1
$ pod trunk register 这里写邮箱  '这里起个名字'   --description= ' 这里写描述'

执行完成之后,会给你的邮箱里发一封邮件,去邮箱点击链接!

然后提交到CocoaPods

(注意:由于我验证podspec文件时使用了--allow-warnings 所以这里后面也加上--allow-warnings)

1
pod trunk push Redirect.podspec --allow-warnings

10, 提交完成后,就可以通过cocopods查找Redirect了

679636-20180111173210410-916162886.png

(注意:)刚提交后项目用pod search命令会搜不到,因为本地的索引没有更新,使用下面命令删除索引文件

1
rm ~/Library/Caches/CocoaPods/search_index.json

最后pod search 命令搜到自己的项目,大功告成

 如果还是不行就再执行

1
rm ~/Library/Caches/CocoaPods/search_index.json
1
pod setup

再进行pod search,

-完美

679636-20180112111815207-1557060535.png

这样就可以进行使用了.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值