美文网首页
CocoaPods私有库创建-要多简单就多简单

CocoaPods私有库创建-要多简单就多简单

作者: 黄梦轩 | 来源:发表于2019-05-08 09:16 被阅读0次

请先安装CocoaPods,步骤可以自行百度,这里略过.

废话不多说,直接上步骤

1. 在gitee创建一个空项目作为私有的远程索引库(HMXRepo)

2. 将私有的远程索引库Copy到本地

pod repo add FERSpecs https://gitee.com/Bu_Jie/HMXRepo.git

执行完成之后,可以在~/.cocoapods/repos目录中看到自己的远程索引库。

3. 创建一个空项目作为私有库(HMXPodTest)

4. 将创建的HMXPodTest克隆到想要放置私有库的位置

cd到将要存放私有库的目录

cd /Users/bujie/HMX/ModulizationDemo 

然后将创建的HMXPodTest克隆到该目录

git clone https://gitee.com/Bu_Jie/HMXPodTest.git

5. 为HMXPodTest添加代码、podspec、LICENSE

  • 拷贝准备好的HMXPodTest.podspecHMXPodTest目录中(你可以从这里拿)
  • 拷贝准备好的LICENSEHMXPodTest目录中你可以从这里拿)
  • HMXPodTest中创建一个新的文件夹,文件夹的命名为HMXPodTest
  • 将代码以及资源拷贝到新创建的文件夹中

最后文件目录的结构如下:

6. 修改HMXPodTest.podspec文件

Pod::Spec.new do |s|
  s.name             = 'HMXPodTest'
  s.version          = '0.1.0'
  s.summary          = 'Podtest'

# This description is used to generate tags and improve search results.
#   * Think: What does it do? Why did you write it? What is the focus?
#   * Try to keep it short, snappy and to the point.
#   * Write the description between the DESC delimiters below.
#   * Finally, don't worry about the indent, CocoaPods strips it!

  s.description      = <<-DESC
TODO: Add long description of the pod here.
                       DESC

  s.homepage         = 'https://gitee.com/Bu_Jie'
  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { '不介' => 'yi.huang@casstime.com' }
  s.source           = { :git => 'https://gitee.com/Bu_Jie/HMXPodTest.git', :tag => s.version.to_s }
  # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

  s.ios.deployment_target = '8.0'

  s.source_files = 'HMXPodTest/Classes/**/*'
  
  # s.resource_bundles = {
  #   'HMXPodTest' => ['HMXPodTest/Assets/*.png']
  # }

  # s.public_header_files = 'Pod/Classes/**/*.h'
  # s.frameworks = 'UIKit', 'MapKit'
  # s.dependency 'AFNetworking', '~> 2.3'
end
  • s.name修改为私有库的名称,这里是HMXPodTest
  • s.summary可以修改为私有库的相关描述
  • s.homepage建议修改为你的主页
  • s.author修改为你自己的信息
  • s.source修改为你创建的私有库的地址
  • s.source_files如果是按照之前描述的目录存储的文件,这里不用修改

7. 修改LICENSE

Copyright (c) 2019 不介 <yi.huang@casstime.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
  • Copyright修改为自己的信息

8. 验证本地库

pod lib lint --allow-warnings --verbose

如果有Error就需要修改,--allow-warnings可以忽略警告

9. 将本地代码推到远程仓库

如果本地库验证通过,就可以把代码推到远程仓库

git remote add origin https://gitee.com/Bu_Jie/HMXPodTest.git
git add .
git commit -m "Initial Commit"
git push -u origin master

10. 为远程仓库打Tags

打Tags的操作必须是在将代码推送到远程仓库之后,而且这个tag必须与HMXPodTest.podspec中的s.version一致。

git tag -m "Initail" 0.1.0
git push --tags

11. 验证远程库

pod spec lint --allow-warnings --verbose

这个命令与pod lib lint类似,区别是这个命令验证的是远程库

12. 注册trunk

pod trunk register 邮箱 '用户名' —descripttion='描述'
  • 邮箱:是gitee上登录的邮箱
  • 用户名:是gitee上的用户名

执行命令后,邮箱中会接收到一封邮件,点击邮件中的链接完成注册

13. 将私有库推送到CocoaPods上

pod trunk push HMXPodTest.podspec 

这条命令可能会等一段时间,请耐心

14. 查看个人信息

pod trunk me
  - Name:    
  - Email:    
  - Since:    May 4th, 00:03
  - Pods:
    - HMXPodTest
  - Sessions:

如果将私有库推送到CocoaPods上成功,Pods中就会有你的私有库的名称

15. 搜索私有库

pod search HMXPodTest

16. 你已经可以告诉你的小伙伴们,他们可以使用你的私有库了

相关文章

网友评论

      本文标题:CocoaPods私有库创建-要多简单就多简单

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