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

环境

CocoaPods 版本:1.15.2 芯片:Apple M1 Pro

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

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

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

Input:

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

Shell 复制代码
pod lib create lsj-FileManager

Output:使用的平台

Shell 复制代码
What platform do you want to use?? [ iOS / macOS ]

Input:

Shell 复制代码
iOS

Output:选择语言

Shell 复制代码
What language do you want to use?? [ Swift / ObjC ]

Input:

Shell 复制代码
ObjC

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

Shell 复制代码
Would you like to include a demo application with your library? [ Yes / No ]

Input:

Shell 复制代码
Yes

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

Shell 复制代码
Which testing frameworks will you use? [ Specta / Kiwi / None ]

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

Shell 复制代码
None

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

Shell 复制代码
Would you like to do view based testing? [ Yes / No ]

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

Shell 复制代码
Yes

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

Shell 复制代码
What is your class prefix?

Input:

Shell 复制代码
L

Output:

Shell 复制代码
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 ,获取路径

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

Input:进入 Example 目录,Pod install

Shell 复制代码
cd Example 
pod install

Output:

Shell 复制代码
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 字段中)

校验我们的 .podspec 文件

Input:

Shell 复制代码
pod lib lint lsj-FileManager.podspec

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

Shell 复制代码
-> 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

Input:

Shell 复制代码
pod lib lint lsj-FileManager.podspec

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

Shell 复制代码
 -> 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

Shell 复制代码
# 进如项目根目录
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 文件中我们可以看到

Shell 复制代码
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 在 .podspec 中 s.version = 0.1.0 这是默认的设置,我们可以自行更改,也可以遵循这个规则

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

Input:

Shell 复制代码
git tag 0.1.0
git push origin 0.1.0

Output:

Shell 复制代码
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:

Shell 复制代码
pod trunk push lsj-FileManager.podspec

Output:

Shell 复制代码
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:

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

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

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

Input:

Shell 复制代码
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

相关推荐
我是谁的程序员8 小时前
iOS 性能分析在 Windows 上怎么做,用 KXBuild 的 kxdevice 替代 Instruments
后端·ios
开心就好20259 小时前
通配符 Bundle ID 和精确 Bundle ID 怎么选,推送、iCloud 能不能用通配符
后端·ios
布莱克60513 小时前
Swift 枚举详解:从基础语法到关联值与模式匹配
开发语言·ios·swift·枚举
茶底世界之下13 小时前
冬日窗边的早餐:用 Awaking 留住冷光里的暖意
ios·app·产品
布莱克60514 小时前
Swift 闭包详解:从语法到实战的完整指南
服务器·开发语言·ios·ssh·swift·闭包
茶底世界之下2 天前
雨后的黄电车:用 Awaking 给灰色街景定一个主角
ios·app·产品
恋猫de小郭2 天前
iOS for Web ,把原生 iOS App 跑到进浏览器里面,倒反天罡
android·前端·ios
00后程序员2 天前
iOS 实时活动怎么开发,Windows 上用 KXBuild 和 ActivityKit 写灵动岛
后端·ios
iReaShare2 天前
如何在没有 Wi-Fi 的情况下备份 iPhone
ios
CocoaKier3 天前
苹果开发者注意,请在2027年1月31日前完成合规验证,否则中国区可能下架
ios·aigc·apple