如何创建一个公有 Pod 库

如何创建一个公有 Pod 库

注意: 文中使用 {} 包裹的位置都需要根据您自身情况进行设置。

如果您已经是 COCOAPODS 用户,请直接跳到第二节。

注册 COCOAPODS 用户

注册 Session

$ pod trunk register {YOURMAIL} '{YOURNAME}' --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.7.2\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nHost: trunk.cocoapods.org\r\nContent-Length: 75\r\n\r\n"
<- "{\"email\":\"YOURMAIL\",\"name\":\"YOURNAME\",\"description\":null}"
-> "HTTP/1.1 201 Created\r\n"
-> "Date: Thu, 20 Jun 2019 14:17:48 GMT\r\n"
-> "Connection: keep-alive\r\n"
-> "Strict-Transport-Security: max-age=31536000\r\n"
-> "Content-Type: application/json\r\n"
-> "Content-Length: 192\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 192 bytes...
-> "{\"created_at\":\"2019-06-20 14:17:48 UTC\",\"valid_until\":\"2019-10-26 14:17:48 UTC\",\"verified\":false,\"created_from_ip\":\"223.104.3.12\",\"description\":null,\"token\":\"xxxxxxxxxx\"}"
read 192 bytes
Conn keep-alive
[!] Please verify the session by clicking the link in the verification email that has been sent to YOURMAIL

去邮箱点击验证链接

此时您的邮箱中应该有一封主题是 [CocoaPods] Confirm your session. 的邮件,点击邮件中的链接进行验证。

验证是否注册成功

下面内容,表示您已经注册成功。

$ pod trunk me
  - Name:     YOURNAME
  - Email:    YOURMAIL
  - Since:    May 23rd, 2018 03:02
  - Pods:
    - PodName
  - Sessions:
    - June 20th, 08:17     -        October 26th, 08:39. IP: xxx.xxx.xxx.xxx

创建公有 Pod 库

创建一个 Git 仓库

创建过程请自行百度,谢谢!!!如果是在搜不到,那就私信我吧!😓

假设我们已经成功创建了一个仓库, 关键信息如下:

创建 Pod 库

在终端中执行: pod lib create {YOURPODNAME},接下来按照提示,根据自己的情况进行选择就可以了。

$ pod lib create {YOURPODNAME}
Cloning `https://github.com/CocoaPods/pod-template.git` into `YOURPODNAME`.
Configuring YOURPODNAME 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. )


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?
 > {Prefix}
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.
security: SecKeychainSearchCopyNext: The specified item could not be found in the keychain.

Running pod install on your new library.

Analyzing dependencies
Fetching podspec for `YOURPODNAME` from `../`
Downloading dependencies
Installing YOURPODNAME (0.1.0)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `YOURPODNAME.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.

 Ace! you're ready to go!
 We will start you off by opening your project in Xcode
  open 'YOURPODNAME/Example/YOURPODNAME.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`.

编辑 YOURPODNAME.podspec

Pod::Spec.new do |s|
  s.name             = '{YOURPODNAME}'
  s.version          = '0.1.0'
  s.summary          = 'A short description of {YOURPODNAME}.'

# 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!

  s.description      = <<-DESC
TODO: Add long description of the pod here.
                       DESC

  s.homepage         = 'https://github.com/{YOURGITHUBNAME}/{YOURPODNAME}'
  # s.screenshots     = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2'
  s.license          = { :type => 'MIT', :file => 'LICENSE' }
  s.author           = { '{YOURNAME}' => '{YOURMAIL}' }
  s.source           = { :git => 'https://github.com/{YOURGITHUBNAME}/{YOURPODNAME}.git', :tag => s.version.to_s }
  # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

  s.ios.deployment_target = '8.0'

  s.source_files = '{YOURPODNAME}/Classes/**/*'
  
  # s.resource_bundles = {
  #   '{YOURPODNAME}' => ['{YOURPODNAME}/Assets/*.png']
  # }

  # s.public_header_files = 'Pod/Classes/**/*.h'
  # s.frameworks = 'UIKit', 'MapKit'
  # s.dependency 'AFNetworking', '~> 2.3'
end

必须要修改的:
s.summary: pod 摘要
s.description: pod 描述
s.homepage: pod 在 github 中的地址
s.author: 作者姓名及邮箱
s.source: pod 的 git 地址

其余的根据您的实际情况进行修改,每个字段的描述,下篇文章中会详细介绍!

验证 YOURPODNAME.podspec

$ pod lib lint

 -> YOURPODNAME (0.1.0)
    - WARN  | summary: The summary is not meaningful.
    - WARN  | url: The URL (https://github.com/{YOURGITHUBNAME}/YOURPODNAME) is not reachable.
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description
    - NOTE  | xcodebuild:  note: Execution policy exception registration failed and was skipped: Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"
    - NOTE  | [iOS] xcodebuild:  warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically.

[!] YOURPODNAME did not pass validation, due to 2 warnings (but you can use `--allow-warnings` to ignore them).
You can use the `--no-clean` option to inspect any issue.

虽然上面还有两个 WARN,但是已经符合官方的标准了,可以进行提交操作了。但是!如果您是完美主义者,可以彻底处理干净后在进行提交!(我解决了,您随意!)

提交代码

$ git add .
$ git commit -m "创建 pod 库"
$ git push

创建并提交 tag

$ git tag -a 0.1.0 -m '创建 pod 库'
$ git push origin --tags

注意: 此处的 tag 应与 .podspec 文件中的 s.version 保持一致。每次修改 pod 中的代码,添加 tag 后,都应同时修改 .podspec 文件中的 s.version

提交 pod

$ pod trunk push

[!] Found podspec `YOURPODNAME.podspec`
Updating spec repo `master`
Validating podspec
 -> YOURPODNAME (0.1.0)
    - NOTE  | xcodebuild:  note: Using new build system
    - NOTE  | [iOS] xcodebuild:  note: Planning build
    - NOTE  | [iOS] xcodebuild:  note: Constructing build description
    - NOTE  | xcodebuild:  note: Execution policy exception registration failed and was skipped: Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"
    - NOTE  | [iOS] xcodebuild:  warning: Skipping code signing because the target does not have an Info.plist file and one is not being generated automatically.

Updating spec repo `master`

--------------------------------------------------------------------------------
 🎉  Congrats

 🚀  YOURPODNAME (0.1.0) successfully published
 📅  June 18th, 10:30
 🌎  https://cocoapods.org/pods/YOURPODNAME
 👍  Tell your friends!
--------------------------------------------------------------------------------

恭喜您,您已经成功的将您创建的 pod 库推送到了官方 pod 库!

坑点 & 解决方案

Failed to open TCP connection to trunk.cocoapods.org:443 (getaddrinfo: nodename nor servname provided, or not known)

解: 此问题常见于 pod trunk 相关的命令。网络大环境不行,要么呢啥(技术都懂的),要么连接手机开热点进行操作。

Unable to accept duplicate entry for: YOURPODNAME (0.1.0)

解: pod trunk push 时发生此错误,说明该 pod 库在远端已经有了 0.1.0 版本。解决方案有两个:

  1. 使用一个远端还没有的版本号
  2. 使用 pod trunk delete YOURPODNAME 0.1.0 删除远端的 0.1.0 版本,然后重新进行推送

unable to find a pod with name, author, summary, or description matching 'YOURPODNAME'

解: 信息更新不及时导致。

首先删除本地缓存

rm ~/Library/Caches/CocoaPods/search_index.json

然后执行:

pod update

Title: 如何创建一个公有 Pod 库

Date: 2019.06.21

Author: zhangpeng

Github: https://github.com/fullstack-zhangpeng

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,242评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,769评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,484评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,133评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,007评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,080评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,496评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,190评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,464评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,549评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,330评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,205评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,567评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,889评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,160评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,475评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,650评论 2 335

推荐阅读更多精彩内容