美文网首页
创建自己的Pod库

创建自己的Pod库

作者: Co_Coder | 来源:发表于2019-11-05 18:25 被阅读0次

目的:创建一个自己的Pod库

例中创建的库名为 'SLFirstFrame'

1.终端自动生成demo

终端cd到自己创建的文件夹根目录下。
在终端执行代码

#your_podName为自己要创建的库的名称   例中使用 SLFirstFrame
pod lib create your_podName

执行以上代码后会出现以下的问题


1.What platform do you want to use? [ iOS / macOS ]  根据自己情况选择平台 - - 此例选择iOS

2.What language do you want to use? [ Swift / ObjC ] 语言- - 此例选择ObjC

3.Would you like to include a demo application with your library? [ Yes / No ] 这里我们需要pod自动为我们生成一个Demo, - - 此例选择Yes

4.Which testing frameworks will you use? [ Specta / Kiwi / None ] 否需要依赖库,根据实际情况选择.暂选None

5.Would you like to do view based testing? [ Yes / No ] 这里是否需要视图测试,暂选No

6.What is your class prefix? 这里是创建时,pod为我们生成的类的前缀,我填写的是SL

demo创建成功后会自动打开创建的文件中 Example下面的项目

创建的demo文件结构

2.创建自己的库文件

  • 新建一个类分别在h文件暴露调用方法,并在m文件中实现。
    方便之后测试时调用验证。

  • 将建好的文件放到图中3位置中的Classes里面,并删除文件夹中的ReplaceMe.m文件

  • cd 到2中的Example目录下,执行pod install (在目录下的Development Pods中会增加你所添加的内容)


    变化后的结构

3.在GitHub上创建对应的Repository

在工程中修改.podspec里面的配置

#
# Be sure to run `pod lib lint SLFirstFrame.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
  s.name             = 'SLFirstFrame'
  s.version          = '0.0.1'
  s.summary          = '第一次创建自己的pod库'

# 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.
我的pod库
                       DESC

  s.homepage         = 'https://github.com/shilei2015/SLFirstFrame'
  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { 'shilei2015' => '244235126@qq.com' }
  s.source           = { :git => 'https://github.com/shilei2015/SLFirstFrame.git', :tag => s.version.to_s }
  # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

  s.ios.deployment_target = '8.0'

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

  # s.public_header_files = 'Pod/Classes/**/*.h'
  # s.frameworks = 'UIKit', 'MapKit'
  # s.dependency 'AFNetworking', '~> 2.3'
end

4.发布项目

关联,提交本地仓库,并将本地的仓库与第三步中创建的远程仓库关联。
cd到图1 ‘ SLFirstFrame’目录下
终端执行

git remote add origin your_github_project_git_url
git add .
git commit -m 'first commit'
git push -u origin master
git tag 0.1.0
git push origin 0.1.0

可能遇到的问题

git remote add origin **************
fatal: remote origin already exists.(报错远程起源已经存在。)

以下是网上摘取的解决办法,
解决办法如下:

1、先输入 git remote rm origin
2、再输入 git remote add origin **************

5.使用

项目中使用
pod 'SLFirstFrame',:git => "https://github.com/shilei2015/SLFirstFrame"

6.更新

将podspec推送到cocoapods仓库
这里注意,推送spec需要先注册个人的邮箱,如果没有注册过或者注册过已经过期,需要重新验证。安全其见,先查看一下当前验证的邮箱信息。
pod trunk me

如果邮箱有误,会报红让我们重新注册或者验证。反之说明邮箱已经注册过,就不需要二次注册验证了。

注册trunk,填写个人邮箱的信息用户名,并登陆邮箱验证即可。
pod trunk register your_email 'your_user_name' --verbose

发布 ,注册成功或已注册的,可以先本地验证一下spec是否正确合法。也可以直接推送至远程,但是这个过程相对很耗时,为了一次性通过,我们先选择本地验证一下。

1.cd到spec所在的目录路径,然后执行pod lib lint
2.若本地验证通过后,再执行pod trunk push --allow-warnings,推送至远程。这个过程pod会自动更改本地的spec文件索引,否则找寻不到自己的库

7.验证使用

pod 'SLFirstFrame'

项目中引入并调用

该内容仅为学习和巩固,方便查看
原文参考

相关文章

网友评论

      本文标题:创建自己的Pod库

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