1、创建pod模板
pod lib create 公有库名字
What platform do you want to use?? [ iOS / macOS ]
> iOS
What language do you want to use?? [ Swift / ObjC ]
> ObjC
Would you like to include a demo application with your library? [ Yes / No ]
> Yes
Which testing frameworks will you use? [ Specta / Kiwi / None ]
> None
Would you like to do view based testing? [ Yes / No ]
> No
What is your class prefix?
> CC
随后会开始创建项目,项目路径如下
.
├── Example --demo位置
│ ├── Podfile
│ ├── Podfile.lock
│ ├── Pods
│ ├── Tests
│ ├── podDemo
│ ├── podDemo.xcodeproj
│ └── podDemo.xcworkspace
├── LICENSE
├── README.md
├── _Pods.xcodeproj -> Example/Pods/Pods.xcodeproj
├── podDemo
│ ├── Assets --资源位置(xib、mp3)
│ └── Classes --源代码位置
└── podDemo.podspec
10 directories, 5 files
2、将此仓库关联远端仓库 我们这面关联的是github
git remote add origin 公有库地址
3、修改podspec文件
Pod::Spec.new do |s|
s.name = 'CCWechat'
s.version = '0.1.0'
s.summary = 'A short description of CCWechat.' - 初始化后必须修改
s.description = <<-DESC - 初始化后必须修改
TODO: Add long description of the pod here.
DESC
s.homepage = '公有库地址'- 初始化后必须修改
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { '彭盛凇' => '个人邮箱' }- 初始化后必须修改
s.source = { :git => '公有库地址', :tag => s.version.to_s }- 初始化后必须修改
s.ios.deployment_target = '9.3'- 初始化后必须修改
s.source_files = 'CCWechat/Classes/**/*'
#s.xcconfig = {
#'VALID_ARCHS' => 'arm64 x86_64',
#} 不支持i386时开启
#s.resources = 'CCActiveNotification/Assets/**/*' 资源
s.dependency 'JPush', '3.1.2'
s.dependency 'QQ_XGPush', '3.3.3-beta'
end
4、本地验证
基础命令
pod lib lint 公有库名字.podspec
如果创建的公有库中的依赖库包含.a静态库时,在基础命令后拼接
--use-libraries --allow-warnings
如果要打印详细信息,在基础命令后拼接
--verbose
eg:
pod lib lint 公有库名字.podspec --use-libraries --allow-warnings --verbose
可选
pengchengsongdeMacBook-Pro:~ pengchengsong$ pod lib lint --help
Usage:
$ pod lib lint
Validates the Pod using the files in the working directory.
Options:
--quick Lint skips checks that would
require to download and build
the spec
--allow-warnings Lint validates even if warnings
are present
--subspec=NAME Lint validates only the given
subspec
--no-subspecs Lint skips validation of
subspecs
--no-clean Lint leaves the build directory
intact for inspection
--fail-fast Lint stops on the first failing
platform or subspec
--use-libraries Lint uses static libraries to
install the spec
--sources=https://github.com/artsy/Specs,master The sources from which to pull
dependent pods (defaults to
https://github.com/CocoaPods/Specs.git).
Multiple sources must be
comma-delimited.
--private Lint skips checks that apply
only to public specs
--swift-version=VERSION The SWIFT_VERSION that should be
used to lint the spec. This
takes precedence over a
.swift-version file.
--skip-import-validation Lint skips validating that the
pod can be imported
--skip-tests Lint skips building and running
tests during validation
--silent Show nothing
--verbose Show more debugging information
--no-ansi Show output without ANSI codes
--help Show help banner of specified
command
5、将本地pod相关所有文件推送到远端,并打上对应的tag
6、注册trunk(已注册可跳过)
pod trunk register eloy@example.com --description='Work Laptop'
8、推送公有库到CocoaPods
基础命令
pod trunk push 公有库名字.podspec
如果创建的公有库中的依赖库包含.a静态库时,在基础命令后拼接
--use-libraries --allow-warnings
如果要打印详细信息,在基础命令后拼接
--verbose
eg:
pod trunk push 公有库名字.podspec --use-libraries --allow-warnings --verbose
可选
pengshengsong-MacBookPro:~ pengchengsong$ pod trunk push --help
[!] No podspec found in directory `.`
Usage:
$ pod trunk push [PATH]
Publish the podspec at `PATH` to make it available to all users of the
‘master’ spec-repo. If `PATH` is not provided, defaults to the current
directory.
Before pushing the podspec to cocoapods.org, this will perform a local
lint of the podspec, including a build of the library. However, it remains
*your* responsibility to ensure that the published podspec will actually
work for your users. Thus it is recommended that you *first* try to use
the podspec to integrate the library into your demo and/or real
application.
If this is the first time you publish a spec for this pod, you will
automatically be registered as the ‘owner’ of this pod. (Note that ‘owner’
in this case implies a person that is allowed to publish new versions and
add other ‘owners’, not necessarily the library author.)
Options:
--allow-warnings Allows push even if there are lint warnings
--use-libraries Linter uses static libraries to install the spec
--use-modular-headers Lint uses modular headers during installation
--swift-version=VERSION The SWIFT_VERSION that should be used to lint the
spec. This takes precedence over a .swift-version
file.
--skip-import-validation Lint skips validating that the pod can be
imported
--skip-tests Lint skips building and running tests during
validation
--silent Show nothing
--verbose Show more debugging information
--no-ansi Show output without ANSI codes
--help Show help banner of specified command
9、更新repo
pod repo update master
10、search 公有库
pod search 公有库名字
其他命令
查看个人信息
pod trunk me
~/.cocoapods/repos
#遇到的坑
1、
pengchengsongdeMacBook-Pro:DataPersistence pengchengsong$ pod lib lint
-> DataPersistence (1.0.0)
- ERROR | name: The name of the spec should match the name of the file.
- ERROR | [iOS] frameworks: A framework should only be specified by its name
- ERROR | [iOS] unknown: Encountered an unknown error (No podspec found for `DataPersistence` in `/Users/pengchengsong/Desktop/DataPersistence/DataPersistence`) during validation.
[!] DataPersistence did not pass validation, due to 3 errors.
You can use the `--no-clean` option to inspect any issue.
出现这个错误是因为,我的podspec 文件名称和里面设置的 ** s.source_files** 和 s.name 不一致导致的,修改为一致的即可!
2、
pengchengsongdeMacBook-Pro:DataPersistence pengchengsong$ pod lib lint
-> PSSDataPersistence (1.0.0)
- ERROR | [iOS] frameworks: A framework should only be specified by its name
- ERROR | [iOS] unknown: Encountered an unknown error (The `PSSDataPersistence` pod failed to validate due to 1 error:
- ERROR | [iOS] frameworks: A framework should only be specified by its name
) during validation.
[!] PSSDataPersistence did not pass validation, due to 2 errors.
You can use the `--no-clean` option to inspect any issue.
pengchengsongdeMacBook-Pro:DataPersistence pengchengsong$
3、pod search找不到自己trunk push的库的解决方法
cd ~/Library/Caches/CocoaPods
删除search_index.json
4、cocoapods官网搜索不到是因为延迟原因,不影响正常开发
5、podspec配置
* Spec Metadata(Spec资料)
* s.name 名称
* s.version 版本
* s.summary 简介
* s.description 详细介绍
* s.homepage 主页地址
* s.screenshots 屏幕截图
* Spec License(Spec执照)
* s.license 开源协议
* Author Metadata(作者资料)
* s.author 作者、邮件地址
* s.authors 多个作者
* s.social_media_url 社交地址
* Platform Specifics(平台特性)
* s.platform 平台
* s.ios.deployment_target ios部署目标
* s.osx.deployment_target osx部署目标
* s.watchos.deployment_target watchos部署目标
* s.tvos.deployment_target tvos部署目标
* Source Location(源定位)
* s.source 开源地址、版本号
* Source Code(源代码)
* s.source_files 开源文件夹、文件
* s.exclude_files 排除文件夹、文件
* s.public_header_files 头文件
* Resources(资源)
* s.resource 资源文件
* s.resources 多个资源文件
* s.preserve_paths 保留路径
* Project Linking(项目关联)
* s.framework 框架
* s.frameworks 多个框架
* s.library 库
* s.libraries 多个库
* Project Settings(项目设置)
* s.requires_arc 需要ARC模式
* s.xcconfig 配置
* s.dependency 依赖Podspecs