美文网首页
git学习之--将自己的库支持CocoaPods

git学习之--将自己的库支持CocoaPods

作者: 沉思的月亮 | 来源:发表于2018-07-17 12:09 被阅读0次

前沿

        上一篇学习了怎么样把自己的本地项目上传到GitHub,接下来学习下怎么将自己的库支持CocoaPods

绑定自己的GitHub账号

请将下面的内容替换为自己的

pod trunk register hz824581849@qq.com 'huangzh' --verbose

由于是第一次注册,下面给我返回了一堆东西

opening connection to trunk.cocoapods.org:443...

opened

starting SSL for trunk.cocoapods.org:443...

SSL established

<- "POST /api/v1/sessions HTTP/1.1\r\nContent-Type: application/json; charset=utf-8\r\nAccept: application/json; charset=utf-8\r\nUser-Agent: CocoaPods/1.5.3\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nHost: trunk.cocoapods.org\r\nContent-Length: 66\r\n\r\n"

<- "{\"email\":\"hz824581849@qq.com\",\"name\":\"huangzh\",\"description\":null}"

-> "HTTP/1.1 201 Created\r\n"

-> "Date: Tue, 17 Jul 2018 01:44:05 GMT\r\n"

-> "Connection: keep-alive\r\n"

-> "Strict-Transport-Security: max-age=31536000\r\n"

-> "Content-Type: application/json\r\n"

-> "Content-Length: 194\r\n"

-> "X-Content-Type-Options: nosniff\r\n"

-> "Server: thin 1.6.2 codename Doc Brown\r\n"

-> "Via: 1.1 vegur\r\n"

-> "\r\n"

reading 194 bytes...

-> "{\"created_at\":\"2018-07-17 01:44:05 UTC\",\"valid_until\":\"2018-11-22 01:44:05 UTC\",\"verified\":false,\"created_from_ip\":\"113.100.139.50\",\"description\":null,\"token\":\"f821028b6ef40fbd35107459fda8a566\"}"

read 194 bytes

Conn keep-alive

[!] Please verify the session by clicking the link in the verification email that has been sent to hz824581849@qq.com

大概意思就是需要去注册的邮箱接收到的邮件,点击链接验证一下。大家应该都懂的,验证后,查看是否注册成功,在终端中执行如下命令

pod trunck me

注册成功,返回注册信息

创建.podspec文件

进入项目根目录,终端输入

pod spec create Test

如果成功,终端输出

Specification created at Test.podspec

设置 podspec 文件内容

这里特别说明一下,之前我自己照着网上的各种版本的教程弄的时候也是反反复复很多次才弄个差不多,其实这里仔细看下,每个说明都会有非常详细的英文说明,只是自己看到英文就很烦,不愿意去仔细翻译。

如果真的没有意愿自己翻译的话,那么尽量不要在网上找各种教程,因为教程很可能都过期了,包括我自己现在写的。

所以个人建议,直接到Github上面看一看优秀的开元框架怎么配置的,这里面我就参考了Alamofire的Alamofire.podspec文件,因为他们的永远是最新的。

下面是Alamofire.podspec 文件的内容(2018-7-8)

Pod::Spec.newdo|s|

s.name='Alamofire'

s.version='4.7.3'

s.license='MIT'

s.summary='Elegant HTTP Networking in Swift'

s.homepage='https://github.com/Alamofire/Alamofire'

s.social_media_url='http://twitter.com/AlamofireSF'

s.authors={'Alamofire Software Foundation'=>'info@alamofire.org'}

s.source={:git=>'https://github.com/Alamofire/Alamofire.git',:tag=> s.version }

s.ios.deployment_target='8.0'

s.osx.deployment_target='10.10'

s.tvos.deployment_target='9.0'

s.watchos.deployment_target='2.0'

s.source_files='Source/*.swift'

end

下面是我自己的Test.podspec文件内容

Pod::Spec.new do |s|

  s.name        = "Test"

  s.version      = "0.0.1"

  s.summary      = "Test."

  s.homepage    = "https://github.com/huang0920hua/Test"

  s.license      = "MIT"

  s.author            = { "huangzh" => "hz824581849@qq.com" }

  s.platform    = :ios

  s.ios.deployment_target = "9.0"

  s.source      = { :git => "https://github.com/huang0920hua/Test.git", :tag => "#{s.version}" }

  s.source_files  = "Source", "Source/**/*.{h,m}"

  # s.public_header_files = "Source/**/*.h"

end

对比一下,几乎就是踩着大神的足迹往前走,其实我个人比较建议这样,因为,他们都是经过了无数次的经验之后总结出来,最简单、最需要设置的东西都写在里面了。

其实这里面相对比较重要的就是:

version(版本号)

ios.deployment_target(iOS项目支持的最低系统)

source_files(资源文件)

这部其实很关键的,因为配置不好的话无法向下进行,而且网上查到的都是乱七八糟的,强烈建议以后类似的问题直接去GitHub看就好了。

配置完以后就可以进行验证了。

验证podspec文件

pod lib lint

如果成功

 ->Test (0.0.1)

Test passed validation.

如果失败,那就要根据错误信息修改podspec文件内容

给项目打上Tag版本,并推送送到GitHub

在进行打tag 之前,确保你已经验证成功.podspec文件以及资源文件等,commit并push到GitHub

给项目打Tag版本

git tag "0.0.1"

注意:

1、只打版本号终端不会有任何输出

2、是git tag+ 版本号,不是pod tag+ 版本号

3、版本号一定要和你的.podspec文件里的s.version = "0.0.1"对应了,不然虽然暂时不会报错,但是push到GitHub的时候也会报错。

将你的tag推送到远程仓库

git push --tags origin master

接下来终端输出:

Total 0 (delta 0), reused 0 (delta 0)

To https://github.com/huang0920hua/Test.git

 * [new tag]        0.0.1 -> 0.0.1

把Podspec文件推送到CocoaPods官方库

pod trunk push Test.podspec

很遗憾,失败来,原因是CocoaPods不允许有重名的库存在,修改Test.podspec名称和里面对应的name配置名称,commit且push到GitHub,把修改后的Podspec文件推到CocoaPods官方库

pod trunk push CldTest.podspec

成功了,输出如下

Updating spec repo `master`

--------------------------------------------------------------------------------

 🎉  Congrats

 🚀  CldTest (0.0.1) successfully published

 📅  July 16th, 21:34

 🌎  https://cocoapods.org/pods/CldTest

 👍  Tell your friends!

--------------------------------------------------------------------------------

搜不到自己的框架

当你做完了以上几步之后,看到的文章都会告诉你,OK,你已经大功告成了。可以直接使用你的框架了。但是,你还是用不了,连搜索都搜不到

pod search CldTest

出现如下信息

[!] Unable to find a pod with name, author, summary, or description matching `CldTest`

别急,这里有解决办法

进入CocoaPods 目录下

~/资源库/Caches/CocoaPods

删除search_index.json这个文件,这个文件是pod search 搜索时的缓存文件。

再试一下,一般来说,这里就可以搜索到来,如果还是搜索不到,别急,执行以下步骤

1、更新本地pod库

pod setup

再删除search_index.json这个文件,再搜索,终于搜出来了

-> CldTest (0.0.1)

   Test.

   pod 'CldTest', '~> 0.0.1'

   - Homepage: https://github.com/huang0920hua/Test

   - Source:  https://github.com/huang0920hua/Test.git

   - Versions: 0.0.1 [master repo]

安装到工程

修改使用工程的Podfile文件,添加一行pod 'CldTest'

进到使用工程的根目录下,终端输入 pod update命令,下载完成后就可以直接使用了。

相关文章

网友评论

      本文标题:git学习之--将自己的库支持CocoaPods

      本文链接:https://www.haomeiwen.com/subject/omcwpftx.html