一、创建 library
- 使用 pod 命令创建 lib
> pod lib create JKCache
- 运行结果
Cloning `https://github.com/CocoaPods/pod-template.git` into `JKCache`.
Configuring JKCache template.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
------------------------------
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 click links to open in a browser. )
...
- 自选配置
- 平台: 选择 iOS 或 MAC
What platform do you want to use?? [ iOS / macOS ]
> iOS
- 开发语言:Swift 或 ObjC
What language do you want to use?? [ Swift / ObjC ]
> ObjC
- 自动生产 Demo 工程 Yes 或 No
Would you like to include a demo application with your library? [ Yes / No ]
> Yes
- 测试框架 Specta、Kiwi 或 None
Which testing frameworks will you use? [ Specta / Kiwi / None ]
> None
- 基于试图测试 Yes 或 No
Would you like to do view based testing? [ Yes / No ]
> Yes
- 项目前缀
What is your class prefix?
> JK
- 运行结果
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
Running pod install on your new library.
Analyzing dependencies
Adding spec repo `trunk` with CDN `https://cdn.cocoapods.org/`
CocoaPods 1.9.3 is available.
To update use: `sudo gem install cocoapods`
For more information, see https://blog.cocoapods.org and the CHANGELOG for this version at https://github.com/CocoaPods/CocoaPods/releases/tag/1.9.3
Downloading dependencies
...
Installing JKCache (0.1.0)
Generating Pods project
Integrating client project
[!] Please close any current Xcode sessions and use `JKCache.xcworkspace` for this project from now on.
Pod installation complete! There are 5 dependencies from the Podfile and 5 total pods installed.
Ace! you're ready to go!
We will start you off by opening your project in Xcode
open 'JKCache/Example/JKCache.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`.
library 在当前目录下创建成功
二、编辑 library
- copy 类文件至
··/libName/Classes
文件夹
- copy 资源文件至
··/libName/Assets
文件夹
- 编辑 podspec 文件
Pod::Spec.new do |s|
s.name = 'JKCache'
s.version = '0.1.0'
s.summary = '轻量级缓存库'
# 描述
s.description = <<-DESC
适用于 OC 开发 下的一个轻量级缓存框架
DESC
# 主页
s.homepage = 'https://github.com/jack6231/JKCache'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'jack6231' => '**********@163.com' }
# 仓库地址,tag 与 version 一致
s.source = { :git => 'https://github.com/jack6231/JKCache.git', :tag => s.version.to_s }
s.ios.deployment_target = '8.0'
# 类文件位置
s.source_files = 'JKCache/Classes/**/*'
# 资源文件位置
s.resource_bundles = {
'JKCache' => ['JKCache/Assets/*.png']
}
end
-
完善 Demo
三、上传 gitHub
- GitHub 上创建项目
- 上传 library 至 gitHub
- 创建tag、推送远程仓库
> git tag 0.1.0
> git push origin 0.1.0
四、注册 cocoapods 账号
- 使用 pod 命令注册 cocoapods 账号
> pod trunk register ***********@163.com "Jack" --verbose
- pod 会将验证链接发送至注册邮箱
- 点击邮箱验证链接,继续完成注册
- 查看自己的注册信息
> pod trunk me
- 注册信息
- Name: Jack
- Email: **********1@163.com
- Since: June 3rd, 21:14
- Pods:
- JKCache
- Sessions:
- June 3rd, 21:14 - October 29th, 03:04. IP: 211.94.117.100
五、将 library 同步 cocoapods 索引库
- 添加私有库索引库
> pod repo add JKCache https://github.com/jack6231/JKCache.git
- 添加成功
Cloning spec repo `JKCache` from `https://github.com/jack6231/JKCache.git`
- 查看 repo list
> pod repo
cocoapods
- Type: git (master)
- URL: https://github.com/CocoaPods/Specs.git
- Path: /Users/jack/.cocoapods/repos/cocoapods
JKCache
- Type: git (master)
- URL: https://github.com/jack6231/JKCache.git
- Path: /Users/jack/.cocoapods/repos/JKCache
trunk
- Type: CDN
- URL: https://cdn.cocoapods.org/
- Path: /Users/jack/.cocoapods/repos/trunk
3 repos
- 验证私有库
> pod lib lint
- 验证通过
-> JKCache (0.1.0)
- NOTE | xcodebuild: note: Using new build system
- NOTE | xcodebuild: note: Building targets in parallel
- NOTE | [iOS] xcodebuild: note: Planning build
- NOTE | [iOS] xcodebuild: note: Constructing build description
- NOTE | [iOS] xcodebuild: warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically. (in target 'App' from project 'App')
- NOTE | [iOS] xcodebuild: note: Execution policy exception registration failed and was skipped: Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted" (in target 'JKCache' from project 'Pods')
- NOTE | [iOS] xcodebuild: note: Execution policy exception registration failed and was skipped: Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted" (in target 'Pods-App' from project 'Pods')
- NOTE | [iOS] xcodebuild: note: Execution policy exception registration failed and was skipped: Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted" (in target 'App' from project 'App')
JKCache passed validation.
- 如果检查有错误警告,可以使用 Demo 工程调试
- 同步 library 索引至 cocoapods 索引库
> pod trunk push JKCache.podspec --use-libraries --allow-warnings
- 同步成功
--------------------------------------------------------------------------------
🎉 Congrats
🚀 JKCache (0.1.0) successfully published
📅 June 4th, 00:16
🌎 https://cocoapods.org/pods/JKCache
👍 Tell your friends!
--------------------------------------------------------------------------------
- 验证是否成功提交 cocoapods
- 移除刚才添加私有库 repo
> pod repo remove JKCache
> pod repo
cocoapods
- Type: git (master)
- URL: https://github.com/CocoaPods/Specs.git
- Path: /Users/jack/.cocoapods/repos/cocoapods
trunk
- Type: CDN
- URL: https://cdn.cocoapods.org/
- Path: /Users/jack/.cocoapods/repos/trunk
2 repos
- 更新索引库
> pod repo update
- pod search 刚才上传的私有库
> pod search JKCache
-> JKCache (0.1.0)
轻量级缓存库
pod 'JKCache', '~> 0.1.0'
- Homepage: https://github.com/jack6231/JKCache
- Source: https://github.com/jack6231/JKCache.git
- Versions: 0.1.0 [cocoapods repo]
- 添加成功
提交成功审核需要一定时间,隔天再搜索看是否搜索的到
所有私有库,需要将自己添加的 repo 移除
若库有更新重新执行步骤五