利用cocoapods管理开源项目,支持 pod install安装整个流程记录(github公有库),完成预期的任务,大体有下面几步:javascript
1.代码提交到github平台html
2.建立.podspecjava
3.编辑.podspecios
4.添加taggit
5.验证github
6.注册CocoaPodsjson
7.发布swift
不是惟一的,上传到任何平台上均可以,前提是项目是开源的)。至于怎么利用github管理咱们的项目,能够参考:http://www.cnblogs.com/richard-youth/p/4684100.html
注
yooweiTest这个是你框架的名称)
$ pod spec create
yooweiTest
yooweiTestyooweiTesthttps://github.com/yoowei/yooweiTest s.license= { :type => "MIT", :file => "LICENSE" }
https://github.com/yoowei/yooweiTest.git.git结尾。
s.source_files = "yooweitest", "yooweitest/**/*" //须要和.podspec 的名称同样??Pod::Spec.new do |s| s.name = ""
s.version = "1.0"
s.ios.deployment_target = '7.0'
s.summary = ""
s.homepage = ""
s.author = { "yoowei" => "yoowei@126.com" }
s.source = { :git => "", :tag => s.version } /注意须要
接下来说解一下每行代码的含义
s.name:名称,pod search 搜索的关键词,注意
这里必定要和.podspec的名称同样,不然报错
s.license= { :type => "MIT", :file => "LICENSE" }
这里建议你们这样写,若是写别的会报警告,致使后面一直提交失败
建议
你们写第一种或者第二种 "yooweitest/* "yooweitest/yoowei/*.{h,m}" "yooweitest/**/*.h"
s.source = { :git => "https://github.com/yoowei/yooweiTest.git", :commit => "68defea" } s.source = { :git => "https://github.com/yoowei/yooweiTest.git", :tag => 1.0.0 } s.source = { :git => "https://github.com/yoowei/yooweiTest.git", :tag => s.version }
// 引用libxml2.lib和libz.lib.
spec.libraries = 'xml2', 'z'
二、引用公有framework:"(.ios).framework" 用”,”分割. 去掉尾部的”.framework”
spec.frameworks = 'UIKit','SystemConfiguration', 'Accelerate'
三、引用本身生成的framework:’(.ios).vendored_frameworks’ 用”,”分割 路径写从.podspec所在目录为根目录的相对路径 ps:这个不要省略.framework spec.ios.vendored_frameworks = 'Pod/Assets/*.framework'
四、引用本身生成的.a文件, 添加到Pod/Assets文件夹里. Demo的Example文件夹里也须要添加一下, 否则找不到
spec.ios.vendored_libraries = 'Pod/Assets/*.a'
注意:在提交到私有仓库的时候须要加上--use-libraries
MIT LicenseCopyright (c) 2017Permission is hereby granted, free of charge, to any person obtaining a copyvim
of this software and associated documentation files (the "Software"), to dealxcode
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
// --verbose 若是验证失败会报错误信息
$ pod spec lint yooweiTest.podspec --verbose
一、
-> yooweiTest (1.0)
- WARN | github_sources: Github repositories should end in `.git`. //注意须要以.git结尾
- WARN | description: The description is equal to the summary.
- NOTE | xcodebuild: warning: no rule to process file 'yooweiTest/JSPatchtest/yoowei/JSPatch.js' of type sourcecode.javascript for architecture i386
- NOTE | xcodebuild: warning: no rule to process file 'yooweiTest/JSPatchtest/yoowei/JSPatch.js' of type sourcecode.javascript 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).
[!] 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`.
$ pod lib lint --allow-warnings
$ echo "2.3" > .swift-version
二、 -> JSPatchtest (1.0.0)
- ERROR | name: The name of the spec should match the name of the file.// 这个是要保证.podspe文件的名称和里面s.name保持一致
- WARN | github_sources: Github repositories should end in `.git`.
- WARN | description: The description is equal to the summary.
- ERROR | [iOS] unknown: Encountered an unknown error (No podspec found for `JSPatchtest` in `/Users/galahad/Desktop/yooweiTest`) during validation.
[!] JSPatchtest did not pass validation, due to 2 errors and 2 warnings.
3 、
[!] Error installing JSPatchtest
-> yooweitest (1.0.0)
- WARN | description: The description is shorter than the summary.
- ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://github.com/yoowei/yooweiTest.git /var/folders/rg/gmjp61bx0x95t4tjx2hh_3sr0000gn/T/d20170113-4028-cvivmq --template= --single-branch --depth 1 --branch 1.0.0
[!] The spec did not pass validation, due to 1 error and 1 warning.
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
(-switch 后面加上你的Xcode.app包内容里的Developer的文件夹路径便可).
[!] The spec did not pass validation, due to 1 error.
pod --version
命令查看版本,若是CocoaPods版本低,须要升级。已经注册过的不须要注册,怎么看本身有没有注册
$ pod trunk me
- Name: yoowei
// 加上--verbose能够输出详细debug信息,方便出错时查看。
$ pod trunk register yoowei@126.com "yoowei" --verbose
--allow-warningspod trunk push yooweiTest.podspec
成功了之后会出现如下内容
$ pod search yoowei
[!] Unable to find a pod with name, author, summary, or description matching `yoowei`
pod setup
成功后会生成~/Library/Caches/CocoaPods/search_index.json
文件。
终端输入rm ~/Library/Caches/CocoaPods/search_index.json
删除成功后再执行pod search 一切OK🌶
$ rm ~/Library/Caches/CocoaPods/search_index.json
$ pod search yoowei
Creating search index for spec repo 'master'.. Done!
$ pod search yoowei
-> yooweiTest (1.0)
yooweiTest just test.
pod 'yooweiTest', '~> 1.0'
- Homepage: https://github.com/yoowei/yooweiTest
- Source: https://github.com/yoowei/yooweiTest.git
- Versions: 1.0 [master repo]