CocoaPods私有库的创立-iOS

  • 默认敞开VPN
  • 无指定说明终端命令都cd到本地项目最外层

1.创立库房

github:Your repositorites  ->  New -> Repository name*  中输入库房名 -> Create repository  (其他选项默认)

2.创立项目

终端

cd 一个项目寄存途径
pod lib create xxx(DEACRollingNumberLabel) (项目称号 最好跟库房名共同)
ryan@RyandeMac-mini Documents % pod lib create DEACRollingNumberLabel
Cloning `https://github.com/CocoaPods/pod-template.git` into `DEACRollingNumberLabel`.
Configuring DEACRollingNumberLabel template.
------------------------------
To get you started we need to ask a few questions, this should only take a minute.
If this is your first time we recommend running through with the guide: 
 - https://guides.cocoapods.org/making/using-pod-lib-create.html
 ( hold cmd and double click links to open in a browser. )
What platform do you want to use?? [ iOS / macOS ] // 挑选渠道
 > ios
What language do you want to use?? [ Swift / ObjC ] // 挑选语言
 > swfit
Would you like to include a demo application with your library? [ Yes / No ] // 是否增加demo
 > Yes
Which testing frameworks will you use? [ Quick / None ] // 是否运用Framwork框架
 > None
Would you like to do view based testing? [ Yes / No ] // 否需求做接界面调试test
 > No
Running pod install on your new library.
Analyzing dependencies
Downloading dependencies
Installing DEACRollingNumberLabel (0.1.0)
Generating Pods project
Integrating client project
[!] Please close any current Xcode sessions and use `DEACRollingNumberLabel.xcworkspace` for this project from now on.
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod 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 'DEACRollingNumberLabel/Example/DEACRollingNumberLabel.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`.

成功后会主动创立并打开Xcode显现该项目

项目目录

CocoaPods私有库的创立-iOS版

根目录

CocoaPods私有库的创立-iOS版

3.导入要害代码文件

.podspec的描绘中已给出相应的途径

s.source_files = 'DEACRollingNumberLabel/Classes/**/*'

只需求把该目录下的文件替换掉即可

CocoaPods私有库的创立-iOS版

4.本地项目相关至github库房

终端 cd 到本地项目根目录

ryan@RyandeMac-mini Documents % cd /Users/ryan/Documents/DEACRollingNumberLabel

任何履行一下命令

git add .
git commit -m "xxx" // 提交或更新的内容描绘
git branch -M main
git remote add origin xxx (https://github.com/zhigangwu/DEACRollingNumberLabel.git) // 此处为github上项目源(source)地址 
git push -u origin main
履行 git push -u origin main 回来如下信息表面相关成功 改写github上的库房即可看到上传的内容
ryan@RyandeMac-mini DEACRollingNumberLabel % git push -u origin main
Enumerating objects: 71, done.
Counting objects: 100% (71/71), done.
Delta compression using up to 8 threads
Compressing objects: 100% (64/64), done.
Writing objects: 100% (71/71), 27.22 KiB | 6.80 MiB/s, done.
Total 71 (delta 16), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (16/16), done.
To https://github.com/zhigangwu/DEACRollingNumberLabel.git
 * [new branch]      main -> main
branch 'main' set up to track 'origin/main'.

github库房相关后目录

CocoaPods私有库的创立-iOS版

5.修正.podspec内容

.podspec默认内容

Pod::Spec.new do |s|
  s.name             = 'DEACRollingNumberLabel'  // 库称号,不能跟现有cocoapods库房里的库名同名
  s.version          = '0.1.0' // 版别号 延迟到第五步修正
  s.summary          = 'A short description of DEACRollingNumberLabel.' // 描绘
# 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!
  s.description      = <<-DESC
TODO: Add long description of the pod here.
  // description指的是对库的描绘,平常我们运用pod search 库名的时候,每个库有一个简单的介绍,指的便是这个description
                       DESC
  s.homepage         = 'https://github.com/12740181/DEACRollingNumberLabel' // 库房地址 一般都填写git库房的主页URL
  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { '12740181' => '1402832352@qq.com' } // 作者 联系方式
  s.source           = { :git => 'https://github.com/12740181/DEACRollingNumberLabel.git', :tag => s.version.to_s }
// 源地址 及 tag 版别
  # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
  s.ios.deployment_target = '10.0' // 库发布的iOS适配版别号,一般指最低支持的iOS版别
  s.source_files = 'DEACRollingNumberLabel/Classes/**/*' // 库的源码,需求明确指定,pod编译打包库时编译的便是这儿指定的源码,一般都以通配符方式匹配
  # s.resource_bundles = {
  #   'PodspecLib' => ['PodspecLib/Assets/*.png']
  # }
# resource_bundles指的是资源文件,一般指图片、xib、storyboard、配置文件等
  # s.public_header_files = 'Pod/Classes/**/*.h'
  // 开放的公共头
  # s.frameworks = 'UIKit', 'MapKit'
  // 私有库需求依靠系统的哪些framework,需求这儿明确指定
  # s.dependency 'AFNetworking', '~> 2.3'
  // 私有库假如需求依靠其他第三方pod,需求这儿指定,多个时需求同样格式指定多个
end

修正完.podspec文件内容后

cd 到本地目录的Example目录 并履行 pod install
pod 成功后即可在 Example for xxx 模块中进行相应的测试

import xxx 后假如发现无法获取到相应的库文件 则需求在相应的文件中参加 pubilc 权限修饰

测试通过后则进行下一步

6.更新tag

修正.podspec文件

s.version = ‘xxx' // 设置一个当前的tag版别号

终端 cd 到本地项目根目录

cd /Users/ryan/Documents/DEACRollingNumberLabel
git add .
git commit -m 'xxx' // 可描绘为更新xxxtag版别
git push -u origin main
git tag 1.0.0  // 与 s.version 中的共同
git push —tags

改写github线上库房

CocoaPods私有库的创立-iOS版

7.验证.podspec文件

履行命令

pod spec lint --allow-warnings --use-libraries
或
pod lib lint pod_test.podspec --allow-warnings --use-libraries
假如失利,报超时,可多试几次
ryan@RyandeMac-mini DEACRollingNumberLabel % pod spec lint --allow-warnings --use-libraries
 -> DEACRollingNumberLabel (1.0.0)
    - WARN  | [iOS] swift: The validator used Swift `4.0` by default because no Swift version was specified. To specify a Swift version during validation, add the `swift_versions` attribute in your podspec. Note that usage of a `.swift-version` file is now deprecated.
    - NOTE  | xcodebuild:  note: Using codesigning identity override: -
    - NOTE  | [iOS] xcodebuild:  note: Building targets in dependency order
    - NOTE  | [iOS] xcodebuild:  note: Metadata extraction skipped. No AppIntents.framework dependency found. (in target 'App' from project 'App')
Analyzed 1 podspec.
DEACRollingNumberLabel.podspec passed validation. // 证明验证成功
ryan@RyandeMac-mini DEACRollingNumberLabel % 

8.相关到长途索引库

在github上在创立一个库房命名建议xxxSpec,作用便是把本地项目中的xxx.podspec文件与该库房相关起来做一个独自的管理。该库房一起也能够寄存之后要创立的私有库的Spec文件。

创立好之后在生成个 README 以生成一个 main 主目录(没有主目录后续上传.podspec可能会失利)

创立好之后终端履行命令

pod repo
ryan@RyandeMac-mini DEACRollingNumberLabel % pod repo
cocoapods
- Type: git (remotes/origin/master)
- URL:  https://github.com/CocoaPods/Specs.git
- Path: /Users/ryan/.cocoapods/repos/cocoapods
coding-yecczzz-yecctencentspecs
- Type: git (master)
- URL:  https://e.coding.net/YeCcZzz/YeCcTencentSpecs.git
- Path: /Users/ryan/.cocoapods/repos/coding-yecczzz-yecctencentspecs
DEACProgressCardSpec
- Type: git (main)
- URL:  https://github.com/zhigangwu/DEACProgressCardSpec.git
- Path: /Users/ryan/.cocoapods/repos/DEACProgressCardSpec
trunk
- Type: CDN
- URL:  https://cdn.cocoapods.org/
- Path: /Users/ryan/.cocoapods/repos/trunk
zhigangwu-deacprogresscard
- Type: git (main)
- URL:  https://github.com/zhigangwu/DEACProgressCard.git
- Path: /Users/ryan/.cocoapods/repos/zhigangwu-deacprogresscard
5 repos

终端会检索出本地已有的一些私有库,也能够通过

~/.cocoapods/repos

直接查看本地已有的私有库

履行命令

pod repo add AnimationCollectionSpec https://github.com/zhigangwu/AnimationCollectionSpec.git 
// pod repo add <长途寄存.podspec的库房名> + <长途寄存.podspec的库房git地址>
Cloning spec repo `AnimationCollectionSpec` from `https://github.com/zhigangwu/AnimationCollectionSpec.git`
// 会把长途Spec库房的克隆到本地 .cocoapods/repos 中

履行

pod repo 或 ~/.cocoapods/repos 都能够看到新的Sepc库房

履行

pod repo push AnimationCollectionSpec DEACRollingNumberLabel.podspec --allow-warnings --use-libraries
// pod repo push <长途寄存.podspec的库房名> + <本地项目中的xxx.podspec文件名>

相关成功,本地的repos对应的库房内容也会相应的更新

Validating spec
 -> DEACRollingNumberLabel (1.0.0)
    - WARN  | [iOS] swift: The validator used Swift `4.0` by default because no Swift version was specified. To specify a Swift version during validation, add the `swift_versions` attribute in your podspec. Note that usage of a `.swift-version` file is now deprecated.
    - NOTE  | xcodebuild:  note: Using codesigning identity override: -
    - NOTE  | [iOS] xcodebuild:  note: Building targets in dependency order
    - NOTE  | [iOS] xcodebuild:  note: Metadata extraction skipped. No AppIntents.framework dependency found. (in target 'App' from project 'App')
Updating the `AnimationCollectionSpec' repo
Adding the spec to the `AnimationCollectionSpec' repo
 - [Add] DEACRollingNumberLabel (1.0.0)
Pushing the `AnimationCollectionSpec' repo

至此能够找个项目来做验证下在podfile文件中增加如下内容

source 'https://github.com/zhigangwu/AnimationCollectionSpec.git' // 此地址为管理.podspec文件的 Spec 库房的git源地址
pod 'DEACRollingNumberLabel'
保存履行 pod install