[iOS]使用CocoaPods发布私有库

server/2024/9/24 13:17:32/

1.创建私有 Spec 仓库

首先,需要一个私有的 Git 仓库来存放你的 Podspec 文件,这个仓库用于索引你所有的私有 Pods。

  • 在 GitHub 或其他 Git 服务上创建一个新的私有仓库,例如,名为 PrivatePodSpecs
  • 克隆这个仓库到本地:
$ git clone https://github.com/yourusername/PrivatePodSpecs.git

 

 

2.准备你的组件库

确保你的库的代码已经在一个可访问的 Git 仓库中(比如 GitHub 的私有仓库)。库中应该包含:

  • 所有源代码
  • 许可证文件
  • README 文件,说明库的功能和使用方法

3.创建 Podspec 文件

在你的库项目的根目录下,执行以下命令来创建一个基本的 Podspec 文件:

$ pod spec create YourLibrary

这将创建一个名为 YourLibrary.podspec 的文件,其中 YourLibrary 是你的库的名字。CocoaPods 会自动填充一些基本的模板内容到这个文件中。

#
#  Be sure to run `pod spec lint MyComponent.podspec' to ensure this is a
#  valid spec and to remove all comments including this before submitting the spec.
#
#  To learn more about Podspec attributes see https://guides.cocoapods.org/syntax/podspec.html
#  To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#Pod::Spec.new do |spec|# ―――  Spec Metadata  ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― ###  These will help people to find your library, and whilst it#  can feel like a chore to fill in it's definitely to your advantage. The#  summary should be tweet-length, and the description more in depth.#spec.name         = "MyComponent"spec.version      = "0.0.1"spec.summary      = "A short description of MyComponent."# 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!spec.description  = <<-DESCDESCspec.homepage     = "http://EXAMPLE/MyComponent"# spec.screenshots  = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"# ―――  Spec License  ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― ###  Licensing your code is important. See https://choosealicense.com for more info.#  CocoaPods will detect a license file if there is a named LICENSE*#  Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.#spec.license      = "MIT (example)"# spec.license      = { :type => "MIT", :file => "FILE_LICENSE" }# ――― Author Metadata  ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― ###  Specify the authors of the library, with email addresses. Email addresses#  of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also#  accepts just a name if you'd rather not provide an email address.##  Specify a social_media_url where others can refer to, for example a twitter#  profile URL.#spec.author             = { "" => "" }# Or just: spec.author    = ""# spec.authors            = { "" => "" }# spec.social_media_url   = "https://twitter.com/"# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― ###  If this Pod runs only on iOS or OS X, then specify the platform and#  the deployment target. You can optionally include the target after the platform.## spec.platform     = :ios# spec.platform     = :ios, "5.0"#  When using multiple platforms# spec.ios.deployment_target = "5.0"# spec.osx.deployment_target = "10.7"# spec.watchos.deployment_target = "2.0"# spec.tvos.deployment_target = "9.0"# spec.visionos.deployment_target = "1.0"# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― ###  Specify the location from where the source should be retrieved.#  Supports git, hg, bzr, svn and HTTP.#spec.source       = { :git => "http://EXAMPLE/MyComponent.git", :tag => "#{spec.version}" }# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― ###  CocoaPods is smart about how it includes source code. For source files#  giving a folder will include any swift, h, m, mm, c & cpp files.#  For header files it will include any header in the folder.#  Not including the public_header_files will make all headers public.#spec.source_files  = "Classes", "Classes/**/*.{h,m}"spec.exclude_files = "Classes/Exclude"# spec.public_header_files = "Classes/**/*.h"# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― ###  A list of resources included with the Pod. These are copied into the#  target bundle with a build phase script. Anything else will be cleaned.#  You can preserve files from being cleaned, please don't preserve#  non-essential files like tests, examples and documentation.## spec.resource  = "icon.png"# spec.resources = "Resources/*.png"# spec.preserve_paths = "FilesToSave", "MoreFilesToSave"# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― ###  Link your library with frameworks, or libraries. Libraries do not include#  the lib prefix of their name.## spec.framework  = "SomeFramework"# spec.frameworks = "SomeFramework", "AnotherFramework"# spec.library   = "iconv"# spec.libraries = "iconv", "xml2"# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― ###  If your library depends on compiler flags you can set them in the xcconfig hash#  where they will only apply to your library. If you depend on other Podspecs#  you can include multiple dependencies to ensure it works.# spec.requires_arc = true# spec.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }# spec.dependency "JSONKit", "~> 1.4"end

4.编辑 Podspec 文件

打开 YourLibrary.podspec 文件,在编辑器中进行修改,以符合你的库的具体情况。以下是 Podspec 文件的一个例子及其解释:

Pod::Spec.new do |s|s.name         = "YourLibrary"s.version      = "0.0.1"s.summary      = "A short description of YourLibrary."s.description  = <<-DESCAn optional longer description of YourLibrary.DESCs.homepage     = "http://example.com/YourLibrary"s.license      = { :type => "MIT", :file => "LICENSE" }s.author       = { "Your Name" => "you@example.com" }s.source       = { :git => "https://github.com/yourusername/YourLibrary.git", :tag => "#{s.version}" }s.source_files = "Sources/**/*.{h,m,swift}"s.platform     = :ios, '10.0's.swift_version = '5.0'
end
  • name: 库的名称。
  • version: 库的版本号。这个版本应该与 Git 标签(tag)一致。
  • summary: 库的简短描述。
  • description: 库的详细描述。
  • homepage: 库的主页 URL。
  • license: 许可证类型和文件位置。
  • author: 库的作者信息。
  • source: 指定库的源代码位置,通常是一个 Git 仓库。
  • source_files: 指定包括在库中的源文件。
  • platform: 指定库支持的平台及最低版本。
  • swift_version: 指定所需的 Swift 版本。

注意更新你组件库中的标签或分支

MyComponent.podspec 文件中的 s.source 参数,确保其指向正确的 URL 和分支或标签。

先确保你的组件库有你配置这个分支或标签,然后你再配置分支的名称或tag。

标签(Tag):

标签是指向 Git 仓库中某一特定提交的引用,通常用于标记发布点(如版本发布)。标签是静态的,指向特定的提交,不会随着更多的提交而变化。

在 podspec 文件中使用标签,通常意味着你指定了一个稳定的、用于发布的版本。这是最常见的用法,因为这确保了项目的依赖是固定且可预测的。例如:

s.source = { :git => 'https://gitee.com/fzym/my-component.git', :tag => '0.0.1' }

 分支(Branch):

分支是用于开发新功能、修复错误或进行实验而创建的代码的独立线路。创建分支可以让你在不影响主线(通常是 master 或 main 分支)的情况下开发和测试代码。

在 podspec 文件中指定分支,意味着 CocoaPods 将从这个特定分支拉取代码。这通常用于开发阶段,当你想要使用最新的尚未发布的代码时。

s.source = { :git => 'https://gitee.com/fzym/my-component.git', :branch => 'develop' }

这里,develop 分支可能包含最新的开发中的功能和修复。

 

5.验证 Podspec 文件

在完成编辑后,你需要验证 Podspec 文件来确保配置无误:

$ pod lib lint

 这个命令将检查你的 Podspec 文件是否有错误或者遗漏的必要信息。如果一切顺利,你将看到 "passed validation" 的消息。

6.将 Podspec 推送到你的私有 Spec 仓库

推送到私有 Spec 仓库:

一旦 Podspec 文件准备好并且验证通过,可以将其添加到你的私有 Spec 仓库:

$ pod repo add PrivateRepoName https://github.com/yourusername/PrivatePodSpecs.git
$ pod repo push PrivateRepoName YourLibrary.podspec

 这里 PrivateRepoName 是你给你的私有 Spec 仓库设定的本地名称。

重命名仓库:

如果需要重命名仓库,你可以这样做:

$ pod repo remove OldPrivateRepoName
$ pod repo add NewPrivateRepoName https://github.com/yourusername/PrivatePodSpecs.git

查看所有已添加的仓库:

如果你忘记了你为私有仓库设置的本地别名 PrivateRepoName,你可以很容易地查看你的 CocoaPods 配置来找到所有已添加的私有仓库及其别名。这可以通过在终端运行一个简单的命令来完成。

$ pod repo list

6.使用你的私有库

在项目的 Podfile 中指定你的私有 Spec 仓库和库:

source 'https://github.com/yourusername/PrivatePodSpecs.git'
source 'https://cdn.cocoapods.org/'platform :ios, '10.0'target 'YourTarget' douse_frameworks!pod 'YourLibrary', '~> 0.0.1'
end

然后运行:

$ pod install

7.更新库

当你需要更新你的库时:

  • 更新你的库代码。
  • 修改 Podspec 文件中的版本号,并确保更新 tag。
  • 推送新代码到你的库的 Git 仓库,并创建相应的新 tag。
  • 将更新后的 Podspec 推送到私有 Spec 仓库:
$ pod repo push PrivateRepoName YourLibrary.podspec
  • 在使用该库的项目中,运行 pod update 来拉取最新版本。

8.管理权限

由于你的库和 Spec 仓库是私有的,确保只向需要的团队成员和合作者提供访问权限。


http://www.ppmy.cn/server/17968.html

相关文章

安卓如何搜索到蓝牙5.0的扩展广播

首先安卓手机要支持蓝牙5.0 在未设置搜索广播类型时,是无法搜索到扩展广播的 val scanSettings ScanSettings.Builder() .setLegacy(false) // 可以搜索到扩展广播 val scanSettings ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY…

力扣HOT100 - 994. 腐烂的橘子

解题思路&#xff1a; 因为要记录轮数&#xff08;分钟数&#xff09;&#xff0c;所以不能一口气遍历到底&#xff0c;所以不能用深搜&#xff08;bfs&#xff09;&#xff0c;而要用广搜&#xff08;bfs&#xff0c;层序遍历&#xff09;。 先记录下新鲜橘子数&#xff0c;…

2024年深圳杯东三省数学建模联赛A题B题C题D题超详细解题思路与论文解析

《2024深圳杯&东三省数学建模思路代码成品论文》↓↓↓ https://www.yuque.com/u42168770/qv6z0d/zx70edxvbv7rheu7?singleDoc# 选题建议 ok&#xff0c;我也是第一时间拿到了这个深圳杯的题目&#xff0c;下面是2024深圳杯和东三省数学建模的各题难度分析和选题建议&am…

IntelliJ IDEA2020下使用Maven构建Scala 项目

1.创建maven文件 2.进入pom.xml导入依赖 <!--添加spark的依赖--><dependency><groupId>org.apache.spark</groupId><artifactId>spark-core_2.12</artifactId><version>3.2.1</version></dependency><!--添加scala依…

【前端】4. CSS综合案例

1. 模拟新闻界面 <!-- 1.模拟实现新闻界面 --><!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><title>…

为什么近年来机器学习这么火!!

机器学习&#xff08;Machine Learning&#xff09;是一种人工智能&#xff08;AI&#xff09;的分支&#xff0c;它让计算机能够通过数据学习和改进&#xff0c;而无需明确的编程。这意味着机器学习系统可以从经验中学习&#xff0c;逐步提高其性能。它基于统计学和数学算法&a…

【MATLAB源码-第199期】基于MATLAB的深度学习(CNN)数字、模拟调制识别仿真,输出识别率。

操作环境&#xff1a; MATLAB 2022a 1、算法描述 基于深度学习的调制识别系统利用复杂的数学模型和算法来识别和分类从不同来源接收到的无线信号的调制类型。这种技术的应用广泛&#xff0c;特别是在无线通信、电子战、频谱监测和认知无线电等领域中具有重要价值。调制识别系…

springboot springcloud gateway 中的 undertow 禁止接收trace请求(修复漏洞)

1.定义两个类&#xff1a; CustomHttpHandler.java import io.undertow.server.HttpHandler; import io.undertow.server.HttpServerExchange; import io.undertow.util.StatusCodes;public class CustomHttpHandler implements HttpHandler {private final HttpHandler next;…