cocoapods组件化

147 阅读1分钟

组件化步骤

参考文献

juejin.cn/post/692197…

pod lib create dhfTestKit   // dhfTestKit 库名称   , 报错如下,几种情况,说明环境不支持。看下面的手动下载流程

报错 ,应该是网络问题

Cloning https://github.com/CocoaPods/pod-template.git into testPod.

[!] /usr/bin/git clone github.com/CocoaPods/p… testPod

Cloning into 'testPod'...

fatal: unable to access 'github.com/CocoaPods/p…': Failure when receiving data from the peer

[!] /usr/bin/git clone github.com/CocoaPods/p… dhfTestKit

Cloning into 'dhfTestKit'...

fatal: unable to access 'github.com/CocoaPods/p…': Failed to connect to github.com port 443 after 75003 ms: Couldn't connect to server

报错

Configuring dhfTestKit template.

Ignoring ffi-1.15.5 because its extensions are not built. Try: gem pristine ffi --version 1.15.5

/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/dependency.rb:313:in `to_specs': Could not find 'rexml' (~> 3.2.4) - did find: [rexml-3.1.9.1] ( Gem::MissingSpecVersionError )

Checked in 'GEM_PATH=/Users/dhf/.gem/ruby/2.6.0:/Library/Ruby/Gems/2.6.0:/opt/homebrew/Cellar/cocoapods/1.13.0/libexec:/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/gems/2.6.0', execute gem env for more information

以上都是跟网络、配置环境有关系,不如手动下载

手动下载地址,下载完成后,解压并将文件放入你的项目目录中。

github.com/CocoaPods/p…

需要注意s.source_files的项目结构

dhfTestKit/

├── dhfTestKit/

│   └── Pod/

│       └── Classes/

│           ├── YourClass1.h

│           ├── YourClass1.m

│           ├── YourClass2.h

│           ├── YourClass2.m

│           └── ...

└── dhfTestKit.podspec

└── README.md

└── LICENSE

推送代码到GitHub

pod spec lint dhfTestKit.podspec // 验证podspec文件是否正确

git init // 提示Initialized empty Git repository in /Users/dhf/Desktop/dhfTestKit/.git/,证明已经存在,执行下一步即可

git remote add origin gitee.com/7_yy/dhf-te…

git add .

git commit -m "Initial commit"

git push -u origin main

git push origin 0.1.0

git tag 0.1.0

git push origin 0.1.0

更新代码,并更改版本

git add dhfTestKit.podspec

git commit -m "Update version to 0.2.0"

git push origin main

git tag 0.2.0

git push origin 0.2.0

创建项目尝试安装,创建Podfile,指定git => 'gitee.com/7_yy/dhf-te…', :tag => ‘1.0.0’地址


Podfile

platform :ios, '9.0'

target 'MyApp' do

  pod 'dhfTestKit', :git => 'gitee.com/7_yy/dhf-te…', :tag => ‘1.0.0’

end

Pod install