世间吾为圣,孰敢称齐天。
一、CocoaPods开源库代码提交
1、上传代码库至Git库,打个tag
git tag "0.0.1"
git push --tags
一般将文件路径设置为如下图所示:
2、注册 pod trunk
pod trunk register zonghongyan@126.com 'zonghongyan'
- 如果段时间没有收到邮件,可以修改邮箱重新尝试
- 点击邮件中的链接
- 执行pod trunk me查看自己注册信息
首次提交:Confirm your registration
更换机器提交:Confirm your session
[!] Please verify the session by clicking the link in the verification email that has been sent to zonghongyan@126.com
developer:EVNCamera developer$ pod trunk me
- Name: zonghongyan
- Email: zonghongyan@126.com
- Since: August 26th, 03:48
- Pods: None
- Sessions:
- August 26th, 03:48 - January 1st, 2018 03:50\. IP: 111.21.205.202
3、生成.podspec配置文件
pod spec create spec 库名
cd到你的库的根目录,然后pod spec create EVNCamera生成.podspec配置文件
如果上传不只是代码,这里要主要.bundle文件上传路径配置,配置文件代码如下:
1. #
2. # Be sure to run `pod spec lint EVNCamera.podspec' to ensure this is a
3. # valid spec and to remove all comments including this before submitting the spec.
4. #
5. # To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
6. # To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
7. #
8. #
9. Pod::Spec.new do |s|
10. #
11. # ――― Spec Metadata ―――――――――――――――――――――――――――― #
12. #
13. # These will help people to find your library, and whilst it
14. # can feel like a chore to fill in it's definitely to your advantage. The
15. # summary should be tweet-length, and the description more in depth.
16. #
17. #
18. s.name = "EVNCamera" // 填写自己开源库的名字
19. s.version = "0.0.3" // tag标记版本
20. s.summary = "custom camera" // 开源库简述
21. #
22. # This description is used to generate tags and improve search results.
23. # * Think: What does it do? Why did you write it? What is the focus?
24. # * Try to keep it short, snappy and to the point.
25. # * Write the description between the DESC delimiters below.
26. # * Finally, don't worry about the indent, CocoaPods strips it!
27. s.description = <<-DESC
28. EVNCamera: 自定义相机,custom camera
29. DESC
31. s.homepage = "https://github.com/zonghongyan/EVNCamera/blob/master/README.md" // homepage
32. # s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
33. #
34. #
35. # ――― Spec License ―――――――――――――――――――――――――――――――― #
36. #
37. # Licensing your code is important. See http://choosealicense.com for more info.
38. # CocoaPods will detect a license file if there is a named LICENSE*
39. # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
40. #
41. #
42. s.license = "MIT" // 开源库遵循的开源协议
43. # s.license = { :type => "MIT", :file => "https://github.com/zonghongyan/EVNCamera/blob/master/LICENSE" }
44. #
45. #
46. # ――― Author Metadata ―――――――――――――――――――――――――――――――――― #
47. #
48. # Specify the authors of the library, with email addresses. Email addresses
49. # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
50. # accepts just a name if you'd rather not provide an email address.
51. #
52. # Specify a social_media_url where others can refer to, for example a twitter
53. # profile URL.
54. #
55. #
56. s.author = { "zonghongyan" => "renboan@aliyun.com" } // 作者及邮箱
57. # Or just: s.author = "zonghongyan"
58. # s.authors = { "zonghongyan" => "renboan@aliyun.com" }
59. # s.social_media_url = "http://twitter.com/zonghongyan"
60. #
61. # ――― Platform Specifics ―――――――――――――――――――――――――――――― #
62. #
63. # If this Pod runs only on iOS or OS X, then specify the platform and
64. # the deployment target. You can optionally include the target after the platform.
65. #
66. #
67. s.platform = :ios // 开源库运行平台
68. s.platform = :ios, "8.0"
69. #
70. # When using multiple platforms
71. s.ios.deployment_target = "8.0"
72. # s.osx.deployment_target = "10.7"
73. # s.watchos.deployment_target = "2.0"
74. # s.tvos.deployment_target = "9.0"
75. #
76. #
77. # ――― Source Location ―――――――――――――――――――― #
78. #
79. # Specify the location from where the source should be retrieved.
80. # Supports git, hg, bzr, svn and HTTP.
81. #
82. #
83. s.source = { :git => "https://github.com/zonghongyan/EVNCamera.git", :tag => "#{s.version}" } // 开源库源文件地址,及tag版本
84. #
85. #
86. # ――― Source Code ―――――――――――――――――――――――――――― #
87. #
88. # CocoaPods is smart about how it includes source code. For source files
89. # giving a folder will include any swift, h, m, mm, c & cpp files.
90. # For header files it will include any header in the folder.
91. # Not including the public_header_files will make all headers public.
92. #
93. #
94. s.source_files = "EVNCamera", "EVNCamera/*.{h,m}" // 开源库源文件
95. # s.exclude_files = "EVNCamera"
96. s.requires_arc = true // 如果是OC程序,是arc还是mrc
97. # s.public_header_files = "Classes/**/*.h" // 对外开放的头文件
98. #
99. #
100. # ――― Resources ――――――――――――――――――――――――――― #
101. #
102. # A list of resources included with the Pod. These are copied into the
103. # target bundle with a build phase script. Anything else will be cleaned.
104. # You can preserve files from being cleaned, please don't preserve
105. # non-essential files like tests, examples and documentation.
106. #
107. #
108. s.resource = "EVNCamera/EVNCamera.bundle" // 资源文件
109. # s.resources = "Resources/*.png"
110. #
111. # s.preserve_paths = "FilesToSave", "MoreFilesToSave"
112. #
113. #
114. # ――― Project Linking ――――――――――――――――――――――――――― #
115. #
116. # Link your library with frameworks, or libraries. Libraries do not include
117. # the lib prefix of their name.
118. #
119. #
120. # s.framework = "SomeFramework"
121. # s.frameworks = "SomeFramework", "AnotherFramework"
122. #
123. # s.library = "iconv"
124. # s.libraries = "iconv", "xml2"
125. #
126. # ――― Project Settings ――――――――――――――――――――――――― #
127. #
128. # If your library depends on compiler flags you can set them in the xcconfig hash
129. # where they will only apply to your library. If you depend on other Podspecs
130. # you can include multiple dependencies to ensure it works.
131. #
132. # s.requires_arc = true
133. #
134. # s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
135. # s.dependency "JSONKit", "~> 1.4"
136. #
137. end
4、发布代码
验证.podspec合法性
pod spec lint EVNCamera.podspec
发布代码
pod trunk push EVNCamera.podspec //push代码EVNCamera.podspec
developer:EVNCamera developer$ pod trunk push EVNCamera.podspec
Updating spec repo `master`
/Users/developer/.cocoapods/repos/master/Specs/d/d/b/EVNCamera // 更新到本地库
CocoaPods 1.3.1 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.3.1
Validating podspec
-> EVNCamera (0.0.1)
- ERROR | description: The description is empty.
- ERROR | [OSX] unknown: Encountered an unknown error (undefined method `dirname' for nil:NilClass) during validation.
[!] The spec did not pass validation, due to 2 errors.
[!] The validator for Swift projects uses Swift 3.0 by default, if you are using a different version of swift you can use a `.swift-version` file to set the version for your Pod. For example to use Swift 2.3, run:
`echo "2.3" > .swift-version`.
developer:EVNCamera developer$ pod trunk push EVNCamera.podspec
Updating spec repo `master`
CocoaPods 1.3.1 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.3.1
Validating podspec
-> EVNCamera (0.0.1)
[!] Unable to accept duplicate entry for: EVNCamera (0.0.1) // 提示不能重复提交一个tag,这时需要更新tag,重新上传push
developer:EVNCamera developer$ git tag 0.0.2
developer:EVNCamera developer$ git push --tags
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/zonghongyan/EVNCamera.git
* [new tag] 0.0.2 -> 0.0.2
developer:EVNCamera developer$ pod trunk push EVNCamera.podspec
Updating spec repo `master`
CocoaPods 1.3.1 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.3.1](https://github.com/CocoaPods/CocoaPods/releases/tag/1.3.1)
Validating podspec
-> EVNCamera (0.0.2)
Updating spec repo `master`
CocoaPods 1.3.1 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.3.1
--------------------------------------------------------------------------------
🎉 Congrats
🚀 EVNCamera (0.0.2) successfully published
📅 August 26th, 05:27
🌎 https://cocoapods.org/pods/EVNCamera
👍 Tell your friends!
promote:EVNCamera developer$
5、查看你的类库是否同步到本地Specs repo
~/.cocoapods/repos/master // cocoapods的安装目录
pod setup : 初始化
developer:EVNCamera developer$ pod setup
Setting up CocoaPods master repo
$ /usr/bin/git -C /Users/developer/.cocoapods/repos/master pull --ff-only
From https://github.com/CocoaPods/Specs
8bc7cb892cd..19b7f6fbb01 master -> origin/master
Updating 8bc7cb892cd..19b7f6fbb01
Fast-forward
Specs/0/2/d/CHPlugin/1.1.1/CHPlugin.podspec.json | 51 ++++++++++++++++++++++
Specs/1/f/5/PKCTest/0.1.0/PKCTest.podspec.json | 23 ++++++++++
.../3.1.2/AdvancedTableView.podspec.json | 28 ++++++++++++
3 files changed, 102 insertions(+)
create mode 100644 Specs/0/2/d/CHPlugin/1.1.1/CHPlugin.podspec.json
create mode 100644 Specs/1/f/5/PKCTest/0.1.0/PKCTest.podspec.json
create mode 100644 Specs/4/c/7/AdvancedTableView/3.1.2/AdvancedTableView.podspec.json
CocoaPods 1.3.1 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.3.1
Setup completed
pod repo update : 更新仓库
Updating spec repo `artsy`
$ /usr/bin/git -C /Users/developer/.cocoapods/repos/artsy pull --ff-only
Already up-to-date.
Updating spec repo `master`
$ /usr/bin/git -C /Users/developer/.cocoapods/repos/master pull --ff-only
Already up-to-date.
CocoaPods 1.3.1 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.3.1
搜索自己上传的开源库是否存在
pod search EVNCamera
成功之后,可以执行pod search 你的sdk
developer:EVNCamera developer$ pod search EVNCamera
[!] Unable to find a pod with name, author, summary, or description matching `EVNCamera`
developer:EVNCamera developer$ rm ~/Library/Caches/CocoaPods/search_index.json
developer:EVNCamera developer$ pod search EVNCamera
Creating search index for spec repo 'artsy'.. Done!
Creating search index for spec repo 'master'..
也可以通过:cocoapods.org,查询自己的开源库是否上传成功,会有一定的时间延时。
6、测试使用
[!] Unable to find a specification for `EVNCamera (= 0.0.2)`
[!] CocoaPods was not able to update the `master` repo. If this is an unexpected issue and persists you can inspect it running `pod repo update --verbose`
pod repo remove master
Removing spec repo `master`
pod setup
Setting up CocoaPods master repo
CocoaPods 1.3.1 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.3.1
Setup completed
developer:EVNCameraDemo developer$ pod install
Analyzing dependencies
Downloading dependencies
Installing EVNCamera (0.0.3)
Generating Pods project
Integrating client project
[!] Please close any current Xcode sessions and use `EVNCameraDemo.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
二、自建CocoaPods私有Specs
1、前言
在pod setup成功后,你会看到 ~/developer/.cocoapods/repos/ 目录下有master文件,即CocoaPods公有库索引库
私有库Specs repo创建,详见:http://guides.cocoapods.org/making/private-cocoapods.html
2、创建CocoaPods私有Specs repo
既然是私有,一般为自建git库私有Specs源
$ pod repo add REPO_NAME SOURCE_URL // Add your Private Repo to your CocoaPods installation
developer:~ developer$ pod repo add mmbSpec [http://xxx.xxx/zonghongyan/mmbSpec.git](http://xxx.xxx/zonghongyan/mmbSpec.git)
Cloning spec repo `mmbSpec` from `http://xxx.xxx/zonghongyan/mmbSpec.git`
私有Specs repo目录
How to remove a Private Repo
pod repo remove [name]
3、创建私有类库
和CocoaPods开源库提交配置方式类似,主要是.podspec配置文件书写
4、上传类库
检测类库有效性
developer:StatisticsProject developer$ pod spec lint StatisticsProject.podspec
-> StatisticsProject (0.0.1)
- WARN | summary: The summary is not meaningful.
- WARN | [iOS] license: Unable to find a license file
- NOTE | xcodebuild: warning: no rule to process file 'StatisticsProject/StatisticsProject/PrefixHeader.pch' of type sourcecode.c.h for architecture i386
- NOTE | xcodebuild: warning: no rule to process file 'StatisticsProject/StatisticsProject/PrefixHeader.pch' of type sourcecode.c.h for architecture x86_64
Analyzed 1 podspec.
[!] The spec did not pass validation, due to 2 warnings (but you can use `--allow-warnings` to ignore them).
注意:可以忽略警告的
developer:StatisticsProject developer$ pod lib lint --allow-warnings
-> StatisticsProject (0.0.1)
- WARN | summary: The summary is not meaningful.
- WARN | [iOS] license: Unable to find a license file
- NOTE | xcodebuild: warning: no rule to process file '/Users/developer/Desktop/GitLab/StatisticsProject/StatisticsProject/PrefixHeader.pch' of type sourcecode.c.h for architecture i386
- NOTE | xcodebuild: warning: no rule to process file '/Users/developer/Desktop/GitLab/StatisticsProject/StatisticsProject/PrefixHeader.pch' of type sourcecode.c.h for architecture x86_64
StatisticsProject passed validation.
上传类库到私有Specs repo
$ pod repo push REPO_NAME SPEC_NAME.podspec // Add your Podspec to your repo
developer:StatisticsProject developer$ pod repo push mmbSpec StatisticsProject.podspec --allow-warnings
Validating spec
-> StatisticsProject (0.0.1)
- WARN | summary: The summary is not meaningful.
- WARN | [iOS] license: Unable to find a license file
- NOTE | xcodebuild: warning: no rule to process file 'StatisticsProject/StatisticsProject/PrefixHeader.pch' of type sourcecode.c.h for architecture i386
- NOTE | xcodebuild: warning: no rule to process file 'StatisticsProject/StatisticsProject/PrefixHeader.pch' of type sourcecode.c.h for architecture x86_64
Updating the `mmbSpec' repo
Already up-to-date.
Adding the spec to the `mmbSpec' repo
- [Add] StatisticsProject (0.0.1)
Pushing the `mmbSpec' repo
私有Specs repo更新
pod update 会自动更新CocoaPods Specs repo和自建Specs repo
developer:TestTest developer$ pod update --verbose
Update all pods
Preparing
Updating local specs repositories
Updating spec repo `mmbSpec`
$ /usr/bin/git -C /Users/developer/.cocoapods/repos/mmbSpec fetch origin --progress
$ /usr/bin/git -C /Users/developer/.cocoapods/repos/mmbSpec rev-parse --abbrev-ref HEAD
master
$ /usr/bin/git -C /Users/developer/.cocoapods/repos/mmbSpec reset --hard origin/master
HEAD is now at 6b60a16 [Add] StatisticsProject (0.0.1)
Updating spec repo `master`
$ /usr/bin/git -C /Users/developer/.cocoapods/repos/master fetch origin --progress
remote: Counting objects: 6139, done.
remote: Compressing objects: 100% (935/935), done.
remote: Total 6139 (delta 3034), reused 3357 (delta 2696), pack-reused 2431
Receiving objects: 100% (6139/6139), 645.76 KiB | 130.00 KiB/s, done.
Resolving deltas: 100% (4087/4087), completed with 1067 local objects.
From https://github.com/CocoaPods/Specs
8ab8388e910..2523ba3f33c master -> origin/master
$ /usr/bin/git -C /Users/developer/.cocoapods/repos/master rev-parse --abbrev-ref HEAD
master
$ /usr/bin/git -C /Users/developer/.cocoapods/repos/master reset --hard origin/master
Checking out files: 100% (665/665), done.
HEAD is now at 2523ba3f33c [Add] ReveChatSDK 1.0.8
Analyzing dependencies
Inspecting targets to integrate
Using `ARCHS` setting to build architectures of target `Pods-TestTest`: (``)
Finding Podfile changes
- MBProgressHUD
- SDWebImage
- StatisticsProject
Resolving dependencies of `Podfile`
Comparing resolved specification to the sandbox manifest
- MBProgressHUD
- SDWebImage
- StatisticsProject
Downloading dependencies
-> Using MBProgressHUD (1.0.0)
-> Using SDWebImage (3.6)
-> Using StatisticsProject (0.0.1)
- Running pre install hooks
Generating Pods project
- Creating Pods project
- Adding source files to Pods project
- Adding frameworks to Pods project
- Adding libraries to Pods project
- Adding resources to Pods project
- Linking headers
- Installing targets
- Installing target `MBProgressHUD` iOS 6.0
- Installing target `SDWebImage` iOS 5.0
- Installing target `StatisticsProject` iOS 8.0
- Installing target `Pods-TestTest` iOS 8.0
- Running post install hooks
- Writing Xcode project file to `Pods/Pods.xcodeproj`
- Generating deterministic UUIDs
- Writing Lockfile in `Podfile.lock`
- Writing Manifest in `Pods/Manifest.lock`
Integrating client project
Integrating target `Pods-TestTest` (`TestTest.xcodeproj` project)
- Running post install hooks
- cocoapods-stats from
`/usr/local/lib/ruby/gems/2.3.0/gems/cocoapods-stats-1.0.0/lib/cocoapods_plugin.rb`
Sending stats
- MBProgressHUD, 1.0.0
- SDWebImage, 3.6
-> Pod installation complete! There are 3 dependencies from the Podfile and 3 total pods installed.
developer:TestTest developer$
5、私有类库使用
自建Specs使用
在Podfile文件中添加:
1. source '[http://xxx.xxx/zonghongyan/mmbSpec.git](http://xxx.xxx/zonghongyan/mmbSpec.git)' #自建Specs repo
2. source '[https://github.com/CocoaPods/Specs.git](https://github.com/CocoaPods/Specs.git)' #官方Specs repo
3. platform :ios, '8.0'
4. target 'CocoaPodsTest' do
5. pod 'StatisticsProject' , '0.0.1'
6. end
如果没有创建私有Specs,也可以直接引用git源文件的方式使用,如下方式:
私有类库,StatisticsProject.git,必须配置有.podspec文件,并且无Error信息
1. platform :ios, '8.0'
2. target 'CocoaPodsTest' do
3. pod 'EVNCamera', '~>0.0.3'
4. pod 'StatisticsProject' , :git => 'http://xxx.xxx/zonghongyan/StatisticsProject.git' // 桌面CocoaPodsTest工程
5. end