CocoaPods 私有库Spec Repo搭建与使用指南

一、创建私有 Spec Repo

  1. 创建 Git 仓库
    在 Git 服务器(如 GitHub、GitLab)上新建一个空仓库,例如 PrivateSpecs,用于存放私有库的 podspec 文件。
  2. 添加 Spec Repo 到本地
    前往文件夹 ~/.cocoapods/repos
    打开终端,在终端切换到当前目录下,然后进行pod repo add操作 在终端执行以下命令,将私有仓库添加到 CocoaPods 的仓库列表:
csharp 复制代码
#
pod repo add PrivateSpecs git@github.com:your-username/PrivateSpecs.git

替换 your-username 和仓库地址为实际信息,注意使用SSH或者HTTPS方式获取代码。~/.cocoapods/repos的目录下新增加PrivateSpecs文件夹。

二、创建私有库

  1. 生成模板项目

    在 Git 服务器(如 GitHub、GitLab)上新建一个空仓库,例如 DLYCenterModule。存放私有库代码 使用 CocoaPods 模板生成私有库:

    lua 复制代码
    pod lib create DLYCenterModule

    按提示选择配置(语言、Demo 等)。

  1. 配置项目 cd 到Example文件下,然后pod install下,更新Example项目的pod。如图项目中的podspec文件,更改spec。修改s.homepage和s.source为自己git项目内容。新增加的源码放到DLYCenterModule/Classes/目录下。

3.推送代码到 Git 仓库

sql 复制代码
cd DLYCenterModule
git add .
git commit -m "Initial commit"
git remote add origin git@github.com:your-username/DLYCenterModule.git
git push -u origin master

4.打Tag并推送

lua 复制代码
    #注意 tag和s.version = '0.1.0' 的保持一致
    git tag 0.1.0
    git push --tags

三、验证与发布私有库

  1. 本地验证 podspec

    css 复制代码
    pod lib lint --allow-warnings

    若存在警告但可忽略,使用 --allow-warnings

  2. 推送 podspec 到私有 Spec Repo

    css 复制代码
    pod repo push PrivateSpecs DLYCenterModule.podspec --allow-warnings

3.搜索 私有库是否成功

bash 复制代码
#更新PrivateSpecs
pod repo update PrivateSpecs
#搜索 DLYCenterModule
pod search DLYCenterModule

四、使用私有库

  1. 配置 Podfile

    在项目的 Podfile 中添加私有源和依赖:

    bash 复制代码
    # 公有源(可选)
    source 'https://github.com/CocoaPods/Specs.git'
    # 私有源
    source 'https://github.com/your-username/PrivateSpecs.git'
    
    target 'YourProject' do
      pod 'DLYCenterModule'
    end
  2. 安装依赖

    复制代码
    pod install
相关推荐
他们都不看好你,偏偏你最不争气5 小时前
AutoLayout与Masonry:简化iOS布局
ios
2501_916008898 小时前
iOS 抓包工具有哪些?全面盘点主流工具与功能对比分析
android·ios·小程序·https·uni-app·iphone·webview
2501_915921438 小时前
iOS混淆工具实战 视频流媒体类 App 的版权与播放安全保护
android·ios·小程序·https·uni-app·iphone·webview
2501_9160088912 小时前
uni-app iOS 日志与崩溃分析全流程 多工具协作的实战指南
android·ios·小程序·https·uni-app·iphone·webview
2501_9159214313 小时前
iOS混淆工具实战 在线教育直播类 App 的课程与互动安全防护
android·安全·ios·小程序·uni-app·iphone·webview
Digitally15 小时前
没 iCloud, 如何数据从iPhone转移到iPhone
ios·iphone·icloud
笑尘pyrotechnic15 小时前
push pop 和 present dismiss
macos·ui·ios·objective-c·cocoa
Digitally16 小时前
如何将联系人从 iPhone 转移到 Redmi 手机
ios·智能手机·iphone
2501_9151063217 小时前
Charles抓包工具在接口性能优化与压力测试中的实用方法
ios·性能优化·小程序·https·uni-app·压力测试·webview
Winson℡1 天前
在 React Native 层禁止 iOS 左滑返回(手势返回/手势退出)
react native·react.js·ios