iOS多工程架构(二)—— pod库

一、创建远程索引库

1、我们先在GitHub上创建一个organization
 
创建 organization
2、添加一个远程索引库,填写相关信息
 
远程索引库
3、创建本地索引库,并与远程索引库做关联

a、打开终端,pod repo add 本地索引库的名字 远程索引库的地址
例如:pod repo add JerryNetworkManager https://github.com/JerryYJL/JerryNetworkManager.git

b、pod repo查看是否创建成功

二、创建组件

1、开始创建组件

a、cd 到指定目录,然后pod lib create 组件名
例如 pod lib create JerryNetworkManager
b、而后填上项目相关信息,便能成功创建组件

Q:出现问题:

The file /Users/mac/.cocoapods/repos/Yunini/Yuninixsy/Example/Yuninixsy.xcworkspace does not exist.

 

To learn more about the template see `https://github.com/CocoaPods/pod-template.git`.

To learn more about creating a new pod, see `https://guides.cocoapods.org/making/making-a-cocoapod`.

解决方案:先在GitHub上下载CocoaPods/Specs项目地址:https://github.com/CocoaPods/Specs

将解压所得到的这几个文件:Specs、CocoaPods-version、README 拷贝至/Users/电脑用户名/.cocoapods/repos/master文件夹

关联git仓库

打开master路径:cd ~/.cocoapods/repos/master

初始化git:git init

关联仓库:git remote add origin https://github.com/CocoaPods/Specs

如果无法解决 使用

1. 在项目podfile 文件的顶部 写上

source 'https://github.com/CocoaPods/Specs.git' 

即可 (能解决问题 不推荐这么使用)

2.修改hosts地址 添加 

199.232.4.133 raw.githubusercontent.com

另外附上修改hosts的方法

打开终端 输入命令

vim /etc/hosts

此时就会使用vim编辑器打开hosts文件。我们将hosts文件里刚才配置的地址换成新的地址,修改完成后,输入命令:

:wq

然后保存配置即可

 
进入 目录: Example 运行 pod install
 
2、目录相关
 
目录
a、podspec文件

该文件是组件的核心配置中心,看一下podspec语法

Pod::Spec.new do |s|
#  组件名
  s.name             = 'JLNetworkingManager'
#  版本号,与tag标签对应
  s.version          = '0.1.5'
#  组件的描述
  s.summary          = 'A short description of JLNetworking.'

# 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://github.com/JLNetWorking/JLNetworking'
  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
#  开源协议
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
#  作者信息
  s.author           = { 'Jerry' => '110*****@qq.com' }
#  git地址,版本号
  s.source           = { :git => 'https://github.com/JLNetWorking/JLNetworking.git', :tag => s.version.to_s }
  # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

#  支持的iOS最低版本
  s.ios.deployment_target = '11.0'
#  指定Swift编译版本
  s.swift_version = "5.0"
#  内核设置
  s.pod_target_xcconfig = { 'VALID_ARCHS' => 'x86_64 armv7 arm64' }
#  必备项,代码源文件地址,如果有多个目录下则用逗号分开,否则"public_header_files"等不可用
  s.source_files = 'JLNetworking/Classes/**/*'
  
#  公开头文件地址
  # s.public_header_files = 'Pod/Classes/**/*.h'
#  所需的系统framework,多个用逗号隔开,不需要后缀名
  # s.frameworks = 'UIKit', 'MapKit'
#  资源路径
  s.resource_bundles = {
    'JLNetworkingManager' => ['JLNetworkingManager/Assets/**/*']
  }
#  依赖第三方
  s.dependency 'Moya/RxSwift'
  s.dependency 'RxCocoa'
  s.dependency 'HandyJSON'
  s.dependency 'SwiftyJSON'
  s.dependency 'SnapKit'
  
end
b、example文件,主要写demo相关

这个一般都是写demo,给别人看这个组件是怎么用的,还有跑起来是啥效果之类的

c、Podfile文件

这里可以导入你的demo需要的第三方,且不会引入到你的组件里面

use_frameworks!

platform :ios, '11.0'

target 'JLNetworking_Example' do
  pod 'JLNetworkingManager', :path => '../'

  target 'JLNetworking_Tests' do
    inherit! :search_paths
  end
end
d、组件的核心内容

这里就可以开始你的代码秀了

3、上传

git add .

git commit -m 'xxx'

git remote add origin https://github.com/JLNetWorking/JLNetworking.git

git push origin master

git tag 版本号(需与podspec中的版本号一致)

git push --tags

4、podspec验证

pod spec lint --verbose --allow-warnings --sources='https://github.com/JLNetWorking/JLNetworking.git'

解释

--verbose:打印错误

--allow-warnings:允许警告,默认有警告的podspec会验证失败

--sources:如果依赖了其他不包含在官方specs里的pod,则用它来指明源,比如依赖了某个私有库。多个值以逗号分隔

5、推送

推送分为2种情况,一个是私有库的推送,例如公司自己的gitLabel;第二个是公有库,例如前面的GitHub

a、私有库的推送

私有库的推送比较直接

pod repo push JLNetworking JLNetworking.podspec --verbose --allow-warnings --sources=https://github.com/JLNetWorking/JLNetworking.git

b、公有库的推送

公有库的推送就比较麻烦,因为需要推送到cocoapods,所以第一次推送需要注册账号

注册账号
pod trunk register 邮箱 '名字' --description='macbook air' --verbose
注册完会收到一份邮件,需要点击验证,验证完之后可以查看个人信息
pod trunk me
如果信息正确,就可以推送了
pod repo push JLNetworking JLNetworking.podspec --verbose --allow-warnings --sources=https://github.com/JLNetWorking/JLNetworking.git

5、验证

pod search JLNetworkingManager
如果没有搜到,可能就是本地仓库没有更新

更新repo库,然后再搜
pod repo update

 

posted @ 2022-10-05 16:12  徐家汇  阅读(240)  评论(0编辑  收藏  举报