podSpec
中spec
是Specification
的缩略,说明书的意思,用来描述pod的说明信息的。 podSpec
是cocoapods
的一种文件格式,有一套自己的语法,cocoapods官网有详细的说明,链接是guides.cocoapods.org/syntax/pods…。
1.账号注册
$ pod trunk register 邮箱 '用户名' --description='电脑描述'
范例
pod trunk register xxx@outlook.com 'robinmo' --verbose
终端显示如下:
opening connection to trunk.cocoapods.org:443...
opened
starting SSL for trunk.cocoapods.org:443...
SSL established, protocol: TLSv1.2, cipher: ECDHE-RSA-AES128-GCM-SHA256
<- "POST /api/v1/sessions HTTP/1.1\r\nContent-Type: application/json; charset=utf-8\r\nAccept: application/json; charset=utf-8\r\nUser-Agent: CocoaPods/1.6.1\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nHost: trunk.cocoapods.org\r\nContent-Length: 68\r\n\r\n"
<- "{\"email\":\"xxx@outlook.com\",\"name\":\"robinmo\",\"description\":null}"
-> "HTTP/1.1 201 Created\r\n"
-> "Date: Thu, 27 Jun 2019 09:49:05 GMT\r\n"
-> "Connection: keep-alive\r\n"
-> "Strict-Transport-Security: max-age=31536000\r\n"
-> "Content-Type: application/json\r\n"
-> "Content-Length: 194\r\n"
-> "X-Content-Type-Options: nosniff\r\n"
-> "Server: thin 1.6.2 codename Doc Brown\r\n"
-> "Via: 1.1 vegur\r\n"
-> "\r\n"
reading 194 bytes...
-> "{\"created_at\":\"2019-06-27 09:49:04 UTC\",\"valid_until\":\"2019-11-02 09:49:04 UTC\",\"verified\":false,\"created_from_ip\":\"120.36.253.220\",\"description\":null,\"token\":\"5165873ed4f4fd6779beb7be9ec895fc\"}"
read 194 bytes
Conn keep-alive
[!] Please verify the session by clicking the link in the verification email that has been sent to xxx@outlook.com
2.查收邮件
点击邮件的链接就完成了trunk注册流程。
可在终端输入pod trunk me
查看注册信息
格式如下:
- Name: robinmo
- Email: xxx@outlook.com
- Since: June 27th, 03:49
- Pods: None
- Sessions:
- June 27th, 03:49 - November 2nd, 03:54. IP: 120.36.253.220
3.标记tag
cd到项目根目录
如果未标记tag,验证的时候会 fatal: Remote branch 1.0.0 not found in upstream origin(一把tag打成版本号的样子)
$ git tag '1.0.0'
$ git push --tags
4.创建podspec文件
$ pod spec create 项目名称
这时候本地就生成一个“项目名称.podspec”文件
5.用编辑器打开.podspec文件
删除不必要的注释(这里只简单介绍基本用法,所以只用到一部分必须得字段 更多字段请移步http://guides.cocoapods.org/syntax/podspec.html) 编辑的时候会报如下错误,根据提示修改即可
打开spec文件,修改source_files 和 public_header_files
参照:
#
# Be sure to run `pod spec lint RBScrollTextView.podspec' to ensure this is a
# valid spec and to remove all comments including this before submitting the spec.
#
# To learn more about Podspec attributes see https://docs.cocoapods.org/specification.html
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
#
Pod::Spec.new do |spec|
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# These will help people to find your library, and whilst it
# can feel like a chore to fill in it's definitely to your advantage. The
# summary should be tweet-length, and the description more in depth.
#
spec.name = "RBScrollTextView"
spec.version = "1.0.0"
spec.summary = "A horizontal scroll text view"
# 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!
spec.description = "A horizontal scroll text view which can be set in xib or storyboard"
spec.homepage = "https://github.com/robinmo/RBScrollTextView"
# spec.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Licensing your code is important. See https://choosealicense.com for more info.
# CocoaPods will detect a license file if there is a named LICENSE*
# Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
#
spec.license = "MIT"
# spec.license = { :type => "MIT", :file => "FILE_LICENSE" }
# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the authors of the library, with email addresses. Email addresses
# of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
# accepts just a name if you'd rather not provide an email address.
#
# Specify a social_media_url where others can refer to, for example a twitter
# profile URL.
#
spec.author = { "Robinmo" => "xxx@outlook.com" }
# Or just: spec.author = "Robinmo"
# spec.authors = { "Robin" => "robingao@dingtalk.com" }
# spec.social_media_url = "https://twitter.com/Robin"
# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# If this Pod runs only on iOS or OS X, then specify the platform and
# the deployment target. You can optionally include the target after the platform.
#
# spec.platform = :ios
spec.platform = :ios, "9.0"
# When using multiple platforms
# spec.ios.deployment_target = "5.0"
# spec.osx.deployment_target = "10.7"
# spec.watchos.deployment_target = "2.0"
# spec.tvos.deployment_target = "9.0"
# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Specify the location from where the source should be retrieved.
# Supports git, hg, bzr, svn and HTTP.
#
spec.source = { :git => "https://github.com/robinmo/RBScrollTextView.git", :tag => "#{spec.version}" }
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# CocoaPods is smart about how it includes source code. For source files
# giving a folder will include any swift, h, m, mm, c & cpp files.
# For header files it will include any header in the folder.
# Not including the public_header_files will make all headers public.
#
spec.source_files = "ScrollTextView/ScrollTextView/RBScrollTextView/*.{h,m}"
# spec.exclude_files = "Classes/Exclude"
# spec.public_header_files = "Classes/**/*.h"
# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# A list of resources included with the Pod. These are copied into the
# target bundle with a build phase script. Anything else will be cleaned.
# You can preserve files from being cleaned, please don't preserve
# non-essential files like tests, examples and documentation.
#
# spec.resource = "icon.png"
# spec.resources = "Resources/*.png"
# spec.preserve_paths = "FilesToSave", "MoreFilesToSave"
# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# Link your library with frameworks, or libraries. Libraries do not include
# the lib prefix of their name.
#
# spec.framework = "SomeFramework"
# spec.frameworks = "SomeFramework", "AnotherFramework"
# spec.library = "iconv"
# spec.libraries = "iconv", "xml2"
# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
#
# If your library depends on compiler flags you can set them in the xcconfig hash
# where they will only apply to your library. If you depend on other Podspecs
# you can include multiple dependencies to ensure it works.
spec.requires_arc = true
# spec.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
# spec.dependency "JSONKit", "~> 1.4"
end
常用字段:
spec.name = "RBScrollTextView" # 框架名称
spec.version = "1.0.0" # 框架版本号
spec.summary = "A horizontal scroll text view" # 简介
spec.homepage = "https://github.com/robinmo/RBScrollTextView" # 框架主页
spec.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif" # 框架截图
spec.license = "MIT" # 遵守的开源协议
spec.author = { "Robinmo" => "xxx@outlook.com" } # 作者
spec.platform = :ios, "9.0" # 支持平台
spec.source = { :git => "https://github.com/robinmo/RBScrollTextView.git", :tag => "#{spec.version}" }
# 框架的资源路径:路径可以指向远端代码库,也可以指向本地项目,例如:
# 1.指向远端代码库: { :git => "git@git.oschina.net:yoowei/yoowei.git", :tag => "1.0.0" }
# 2.指向本地项目: { :path => 'yoowei', }
spec.source_files = "ScrollTextView/ScrollTextView/RBScrollTextView/*.{h,m}" # pod install时导入的文件
spec.requires_arc = true # 是否支持arc
6.验证spec文件
编辑完podspec文件后需要验证一下这个文件是否可用podspec文件不允许有任何的Warning或者Error 执行命令
$ pod lib lint
通过
-> RBScrollTextView (1.0.0)
- NOTE | xcodebuild: note: Using new build system
- NOTE | [iOS] xcodebuild: note: Planning build
- NOTE | [iOS] xcodebuild: note: Constructing build description
RBScrollTextView passed validation
常见错误
由于笔者也是初次尝试,报错
-> RBScrollTextView.podspec
- ERROR | spec: The specification defined in `/Users/apple/Test/GitHub/RBScrollTextView/RBScrollTextView.podspec` could not be loaded.
[!] Invalid `RBScrollTextView.podspec` file: syntax error, unexpected in, expecting end
...xt view which can be cofiged in xib or storyboard
... ^~
/Users/apple/Test/GitHub/RBScrollTextView/RBScrollTextView.podspec:137: syntax error, unexpected end, expecting end-of-input.
# from /Users/apple/Test/GitHub/RBScrollTextView/RBScrollTextView.podspec:29
# -------------------------------------------
# DESC
> A horizontal scroll text view which can be set in xib or storyboard
# spec.homepage = "https://github.com/robinmo/RBScrollTextView"
# -------------------------------------------
[!] /Users/apple/Test/GitHub/RBScrollTextView/RBScrollTextView.podspec did not pass validation, due to 1 error.
You can use the `--no-clean` option to inspect any issue.
所有的字段的值都是双引号包裹,我是一开始没加引号引起的
解决之后,pod lib lint
找不到command line tools,报错:
-> RBScrollTextView (1.0.0)
- ERROR | [iOS] unknown: Encountered an unknown error (/usr/bin/xcrun simctl list -j devices
xcrun: error: unable to find utility "simctl", not a developer tool or in PATH
) during validation.
[!] RBScrollTextView did not pass validation, due to 1 error.
You can use the `--no-clean` option to inspect any issue.
进Xcode ->Preferences->Locations->Command Line Tools选择Xcode即可,再次pod lib lint
,通过
-> RBScrollTextView (1.0.0)
- NOTE | xcodebuild: note: Using new build system
- NOTE | [iOS] xcodebuild: note: Planning build
- NOTE | [iOS] xcodebuild: note: Constructing build description
RBScrollTextView passed validation
7.push podspec文件
pod trunk push RBScrollTextView.podspec
,经过漫长的等待,提示成功
Updating spec repo `master`
warning: inexact rename detection was skipped due to too many files.
warning: you may want to set your diff.renameLimit variable to at least 27056 and retry the command.
CocoaPods 1.7.2 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.7.2
Validating podspec
-> RBScrollTextView (1.0.0)
- NOTE | xcodebuild: note: Using new build system
- NOTE | [iOS] xcodebuild: note: Planning build
- NOTE | [iOS] xcodebuild: note: Constructing build description
Updating spec repo `master`
CocoaPods 1.7.2 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.7.2
--------------------------------------------------------------------------------
🎉 Congrats
🚀 RBScrollTextView (1.0.0) successfully published
📅 June 27th, 05:53
🌎 https://cocoapods.org/pods/RBScrollTextView
👍 Tell your friends!
--------------------------------------------------------------------------------
网友评论