iOS - 公开的 Cocoapods 仓库创建(开源仓库)

环境

CocoaPods 版本:1.15.2
芯片:Apple M1 Pro

这个场景,我们是为了提供给所有人更加便捷的集成我们的封装好的东西。

创建的方式,官网也有介绍:https://guides.cocoapods.org/

Input:

通过命令 pod lib create 你的仓库名称 创建仓库,我这里以 lsj-FileManager 作为我的仓库名称

pod lib create lsj-FileManager

Output:使用的平台

What platform do you want to use?? [ iOS / macOS ]

Input:

iOS

Output:选择语言

What language do you want to use?? [ Swift / ObjC ]

Input:

ObjC

Output:是否创建演示应用程序Demo

Would you like to include a demo application with your library? [ Yes / No ]

Input:

Yes

Output:您将使用哪些测试框架?

Which testing frameworks will you use? [ Specta / Kiwi / None ]

Input: 我个人认为 Xcode 的 XCTest 挺好的,后续也可以自己加入对应的 XCTest Target

None

Output:需要创建 UI 测试,后续也可以自行加入 Target

Would you like to do view based testing? [ Yes / No ]

Input: 是否要进行基于视图的测试?

Yes

Output:设置工程文件的前缀,这个根据自己的代码规范填写

What is your class prefix?

Input:

L

Output:

Running pod install on your new library.

Analyzing dependencies
Downloading dependencies
Installing FBSnapshotTestCase (2.1.4)
Installing lsj-FileManager (0.1.0)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `lsj-FileManager.xcworkspace` for this project from now on.
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.


[!] Your project does not explicitly specify the CocoaPods master specs repo. Since CDN is now used as the default, you may safely remove it from your repos directory via `pod repo remove master`. To suppress this warning please add `warn_for_unused_master_specs_repo => false` to your Podfile.

 Ace! you're ready to go!
 We will start you off by opening your project in Xcode
  open 'lsj-FileManager/Example/lsj-FileManager.xcworkspace'

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`.

到这里,仓库已经创建好了,终端会打开你的项目

在仓库中,添加我们的代码

在工程的Pods/Development/Pods/lsj-FileManager/目录下,有一个 ReplaceMe 文件,
是存放我们文件的位置,不能直接在 lsj-FileManager 右键 new->File
因为这是一个虚拟路径,需要我们手动导航进入 Classes 目录中,
可以通过右键 ReplaceMe 文件 Show In Finder,进入到 Classes ,获取路径

image

17106007320088.jpg
17106021443681.jpg

在 Example 中去使用它,Example 项目安装你的pod,提供给用户使用 Demo

Input:进入 Example 目录,Pod install

cd Example 
pod install

Output:

Analyzing dependencies
Downloading dependencies
Installing lsj-FileManager 0.1.0
Generating Pods project
Integrating client project
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.

创建 Git 仓库(备用,后续填入 .podspec 文件中的 source 字段中)

17106679122576.jpg

校验我们的 .podspec 文件

Input:

pod lib lint lsj-FileManager.podspec

Output:summary: The summary is not meaningful 需要我们完善 summary

-> lsj-FileManager (0.1.0)
    - WARN  | summary: The summary is not meaningful.
    - NOTE  | url: The URL (https://github.com/lishangjing/lsj-FileManager) is not reachable.
    - NOTE  | xcodebuild:  note: Using codesigning identity override: -
    - NOTE  | [iOS] xcodebuild:  note: Building targets in dependency order
    - NOTE  | [iOS] xcodebuild:  note: Target dependency graph (3 targets)
    - NOTE  | [iOS] xcodebuild:  note: Signing static framework with --generate-pre-encrypt-hashes (in target 'Pods-App' from project 'Pods')
    - NOTE  | [iOS] xcodebuild:  /var/folders/cs/08c4rp4s4_l39wwhn08jt3sc0000gn/T/CocoaPods-Lint-20240317-8175-8r0xaa-lsj-FileManager/App.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.0.99. (in target 'App' from project 'App')
    - NOTE  | [iOS] xcodebuild:  Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.0.99. (in target 'Pods-App' from project 'Pods')
    - NOTE  | [iOS] xcodebuild:  Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.0.99. (in target 'lsj-FileManager' from project 'Pods')

[!] lsj-FileManager did not pass validation, due to 1 warning (but you can use `--allow-warnings` to ignore it).
You can use the `--no-clean` option to inspect any issue.

完善 .podspec 文件中的 s.summary 、 s.description

17106686661897.jpg

Input:

pod lib lint lsj-FileManager.podspec

Output:lsj-FileManager passed validation. 校验通过

 -> lsj-FileManager (0.1.0)
    - NOTE  | xcodebuild:  note: Using codesigning identity override: -
    - NOTE  | [iOS] xcodebuild:  note: Building targets in dependency order
    - NOTE  | [iOS] xcodebuild:  note: Target dependency graph (3 targets)
    - NOTE  | [iOS] xcodebuild:  note: Signing static framework with --generate-pre-encrypt-hashes (in target 'Pods-App' from project 'Pods')
    - NOTE  | [iOS] xcodebuild:  Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.0.99. (in target 'Pods-App' from project 'Pods')
    - NOTE  | [iOS] xcodebuild:  /var/folders/cs/08c4rp4s4_l39wwhn08jt3sc0000gn/T/CocoaPods-Lint-20240317-8554-8ralh0-lsj-FileManager/App.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.0.99. (in target 'App' from project 'App')
    - NOTE  | [iOS] xcodebuild:  Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.0.99. (in target 'lsj-FileManager' from project 'Pods')

lsj-FileManager passed validation.

推送仓库代码到 Git

# 进如项目根目录
git init
git add .
git commit -m 'Initial Commit'
git remote add origin https://github.com/lishangjing-spec/lsj-FileManager.git
git branch -M master
git push -u origin master

在 .podspec 文件中我们可以看到

s.source = { :git => 'https://github.com/lishangjing-spec/lsj-FileManager.git', :tag => s.version.to_s }

这里指的是,我们依赖的下载地址是:
https://github.com/lishangjing-spec/lsj-FileManager.git
同时,指向的是:s.version tag
.podspecs.version = 0.1.0

17106839678932.jpg

这是默认的设置,我们可以自行更改,也可以遵循这个规则

遵循规则,给我们最新的commit打上tag,让仓库能引用到我们的代码

Input:

git tag 0.1.0
git push origin 0.1.0

Output:

Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
To github.com:lishangjing-spec/lsj-FileManager.git
 * [new tag]         0.1.0 -> 0.1.0

推送项目到 Cocoapods

Input:

pod trunk push lsj-FileManager.podspec

Output:

Updating spec repo `trunk`
Validating podspec
 -> lsj-FileManager
    - NOTE  | xcodebuild:  note: Using codesigning identity override: -
    - NOTE  | [iOS] xcodebuild:  note: Building targets in dependency order
    - NOTE  | [iOS] xcodebuild:  note: Target dependency graph (3 targets)
    - NOTE  | [iOS] xcodebuild:  note: Signing static framework with --generate-pre-encrypt-hashes (in target 'Pods-App' from project 'Pods')
    - NOTE  | [iOS] xcodebuild:  Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.0.99. (in target 'Pods-App' from project 'Pods')
    - NOTE  | [iOS] xcodebuild:  /var/folders/cs/08c4rp4s4_l39wwhn08jt3sc0000gn/T/CocoaPods-Lint-20240317-16091-pb1xlo-lsj-FileManager/App.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.0.99. (in target 'App' from project 'App')
    - NOTE  | [iOS] xcodebuild:  Pods.xcodeproj: warning: The iOS Simulator deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 10.0, but the range of supported deployment target versions is 12.0 to 17.0.99. (in target 'lsj-FileManager' from project 'Pods')

Updating spec repo `trunk`

--------------------------------------------------------------------------------
 🎉  Congrats

 🚀  lsj-FileManager (0.1.0) successfully published
 📅  March 17th, 08:27
 🌎  https://cocoapods.org/pods/lsj-FileManager
 👍  Tell your friends!

上传完成

[F&A]

[!] Authentication token is invalid or unverified. Either verify it with the email that was sent or register a new session.

首次上传或过久没上传,需要重新注册

Input:

# 接受 Cocoapods 的邮箱,以及你的名称(例如:帅哥)
pod trunk register 'xxx@qq.com' 'Name'

Output:进入邮箱,找到并打开验证链接

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

Input:

pod trunk push XXXXX.podspec

.podspec 文件的属性介绍

s.name:名称
s.version:版本号
s.summary:总结
s.description:描述
s.homepage:仓库主页(作用于用户访问仓库首页)
s.license:开源协议
s.author:作者
s.source:用户pod时,依赖拉取的地址
s.ios.deployment_target:依赖支持的版本号
s.source_files:项目文件路径
s.resource_bundles:项目资源文件路径
s.dependency:项目绑定的其他三方依赖
s.frameworks:项目绑定的系统 Framework

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 218,204评论 6 506
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 93,091评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,548评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,657评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,689评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,554评论 1 305
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,302评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,216评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,661评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,851评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,977评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,697评论 5 347
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,306评论 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,898评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,019评论 1 270
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,138评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,927评论 2 355

推荐阅读更多精彩内容