push public library to cocoapods

平时开发整理出了一些自己常用的控件啊,方法之类的,每次创建工程的时候,都得拷贝进去,发现将自己的常用的这些东西折腾成一个开源的库,放到cocoapods上,下次使用的时候,直接借助cocoapods就解决,省很多事情,但是在将我自己的开源库添加到cocoapods中遇到了不少问题,先说说自己一步步的操作吧(举个例子:新建一个叫CommonAlertFramework库):

这些基本上都是在terminal下操作:

1、创建

$ pod lib create CommonAlertFramework
这个时候会要求你输入一些内容,按照提示输入就可以了,输入完成之后,如下显示(个人信息,我以*代替)

<p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo;">Cloning `https://github.com/CocoaPods/pod-template.git` into `CommonAlertFramework`.</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo;">Configuring CommonAlertFramework template.</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures; color: #afad24">! </span>Before you can create a new library we need to setup your git credentials.</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;">
</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo;"> What is your email?</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures; color: #34bd26"> > </span>************</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;">
</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures; color: #34bd26">! </span>Setting your email in git to shouyuzhu@hotmail.com</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo; color: rgb(213, 59, 211);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000">  </span>git config user.email "************"</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;">
</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo;">------------------------------</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;">
</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo;">To get you started we need to ask a few questions, this should only take a minute.</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;">
</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo;">If this is your first time we recommend running through with the guide: </p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo; color: rgb(83, 48, 225);"><span style="font-variant-ligatures: no-common-ligatures; color: #000000"> - </span><span style="text-decoration: underline ; font-variant-ligatures: no-common-ligatures">http://guides.cocoapods.org/making/using-pod-lib-create.html</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo; color: rgb(213, 59, 211);"> ( hold cmd and double click links to open in a browser. )</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;">
</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;">
</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo;">What language do you want to use?? [ <span style="text-decoration: underline ; font-variant-ligatures: no-common-ligatures">ObjC</span> / Swift ]</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures; color: #34bd26"> > </span>ObjC</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;">
</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo;">Would you like to include a demo application with your library? [ <span style="text-decoration: underline ; font-variant-ligatures: no-common-ligatures">Yes</span> / No ]</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures; color: #34bd26"> > </span>Yes</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;">
</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo;">Which testing frameworks will you use? [ <span style="text-decoration: underline ; font-variant-ligatures: no-common-ligatures">Specta</span> / Kiwi / None ]</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures; color: #34bd26"> > </span>None</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;">
</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo;">Would you like to do view based testing? [ <span style="text-decoration: underline ; font-variant-ligatures: no-common-ligatures">Yes</span> / No ]</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo;"><span style="font-variant-ligatures: no-common-ligatures; color: #34bd26"> > </span>Yes</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;">
</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo;">What is your class prefix?</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo; color: rgb(52, 189, 38);"> > <span style="font-variant-ligatures: no-common-ligatures; color: #000000">CA</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo; min-height: 13px;">
</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 11px; font-family: Menlo;">Running <span style="font-variant-ligatures: no-common-ligatures; color: #d53bd3">pod install</span> on your new library.</p><div>
</div>
 2、这个时候,它会自动创建一个工程,并打开该工程,工程结构如下: 

3、点开配置信息里面的.podsec文件,如下所示:

#
# Be sure to run `pod lib lint CommonAlertFramework.podspec' to ensure this is a
# valid spec and remove all comments before submitting the spec.
#
# Any lines starting with a # are optional, but encouraged
#
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
  s.name             = "CommonAlertFramework"
  <span style="color:#ff0000;">s.version          = "0.1.0"</span>
  <span style="color:#ff0000;">s.summary          = "A short description of CommonAlertFramework."
  s.description      = <<-DESC
                       An optional longer description of CommonAlertFramework

                       * Markdown format.
                       * Don't worry about the indent, we strip it!
                       DESC</span>
  s.homepage         = "https://github.com/<span style="color:#ff0000;"><GITHUB_USERNAME></span>/CommonAlertFramework"
  # s.screenshots     = "www.example.com/screenshots_1", "www.example.com/screenshots_2"
  s.license          = 'MIT'
  s.author           = { "<span style="color:#ff0000;">UserName</span>" => "<span style="color:#ff0000;">**********</span>" }
  s.source           = { :git => "https://github.com/<span style="color:#ff0000;"><GITHUB_USERNAME></span>/CommonAlertFramework.git", :tag => s.version.to_s }
  # s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'

  s.platform     = :ios, '7.0'
  s.requires_arc = true

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

  # s.public_header_files = 'Pod/Classes/**/*.h'
  # s.frameworks = 'UIKit', 'MapKit'
  # s.dependency 'AFNetworking', '~> 2.3'
end
s.summary s.description 这两个需要修改成你这个 库的概述以及介绍

s.homepage 和 s.source里面标红的地方<GITHUB_USERNAME>要修改成你自己的用户名,或者说这两个后面的地址要改成你这个库在github上的绝对地址,不能有错。

4、所有的文件都是在开发区里面,比如,我们现在要做一个helloworld的弹出框,代码如下(CAHelloWorld):

.h文件

#import <Foundation/Foundation.h>

@interface CAHelloWorld : NSObject

/**
 *  弹出一个hello world的弹出框
 */
+ (void)sayHelloWorld;

@end
.m文件
#import <UIKit/UIKit.h>
#import "CAHelloWorld.h"

@implementation CAHelloWorld

/**
 *  弹出一个hello world的弹出框
 */
+ (void)sayHelloWorld
{
    [[[UIAlertView alloc] initWithTitle:@"Hello" message:@"world" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show];
}
@end

5、文件添加之后,需要运行pod install 或者pod update,否则,你添加的文件,在DEMO工程里是看不到的

6、在DEMO工程里测试正常,开始进行下一步的操作(这个时候,你应该已经将这个工程上传到你的github上去了)

7、发布之前,做个测试:

$ pod lib lint

 -> CommonAlertFramework (0.1.0)
    - WARN  | The summary is not meaningful.
    - WARN  | The description is not meaningful.
    - WARN  | There was a problem validating the URL https://github.com/<GITHUB_USERNAME>/CommonAlertFramework.

[!] CommonAlertFramework did not pass validation.
You can use the `--no-clean` option to inspect any issue.

发现出现了三个警告,在发布到cocoapods上,不能出现任何警告(工程出现警告无所谓)

- WARN  | The summary is not meaningful.
你的summary并没有按要求填写好

- WARN  | The description is not meaningful.
你的description并没有按要求填写好。

summary和description两者不能相同且description要比summary长,否则也会报错

- WARN  | There was a problem validating the URL https://github.com/<GITHUB_USERNAME>/CommonAlertFramework.
路径没有修改好,参考 步骤3的说明

8、修改完成之后,再测试一下,当出现如下的提示的时候,:

$ pod lib lint

 -> CommonAlertFramework (0.1.0)

CommonAlertFramework passed validation.

9、发布之前,新建一个工程测试一下:

Podfile里输入:

pod '<span style="color:#33cc00;">CommonAlertFramework</span>', :git => '<span style="color:#ff0000;">https://github.com/*********/CommonAlertFramework.git</span>'

绿色为我们库的名称,红色为库在github上的地址

pod install

打开测试工程,如果正常使用该库,则表示该库没有问题,准备push到cocoapods上去

10、上传之前,先注册一下(push到cocoapods根据的是每一次的session,否则无权push)

$ pod trunk register <span style="color:#ff0000;">***********</span>
[!] Please verify the session by clicking the link in the verification email that has been sent to <span style="color: rgb(255, 0, 0); font-family: Arial, Helvetica, sans-serif;">***********</span>
(*为你的邮箱地址,如果是第一次使用的话,则输入如下的命令)

pod trunk register <span style="font-family: Arial, Helvetica, sans-serif; color: rgb(255, 0, 0);">********* </span><span style="font-family: Arial, Helvetica, sans-serif;"> "</span><span style="color:#ffff66;font-family: Arial, Helvetica, sans-serif;">CommonAlertFramework</span><span style="font-family: Arial, Helvetica, sans-serif;">"</span>
即在后面加上一个 用户名(个人测试过程中发现,好像是随意的)

你会收到一个连接邮件,点击邮件里的链接即可,会出现如下的提示:

11、设置tag(不知道这货是干嘛的):

$ git tag "0.1.0"
$ <span style="color:#ff0000;">git push --tags</span>
Total 0 (delta 0), reused 0 (delta 0)
To https://github.com/******/CommonAlertFramework.git
 * [new tag]         0.1.0 -> 0.1.0

红色的这个你必须的执行

12、push到cocoapods

$ pod trunk push CommonAlertFramework.podspec 
Updating spec repo `master`

CocoaPods 0.38.0.beta.1 is available.
To update use: `gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information see http://blog.cocoapods.org
and the CHANGELOG for this version http://git.io/BaH8pQ.

Validating podspec
 -> CommonAlertFramework (0.1.0)

Updating spec repo `master`

CocoaPods 0.38.0.beta.1 is available.
To update use: `gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information see http://blog.cocoapods.org
and the CHANGELOG for this version http://git.io/BaH8pQ.

  - Data URL: https://raw.githubusercontent.com/CocoaPods/Specs/a96ed674714c60b95aeaacbd5c4fa732ce17c988/Specs/CommonAlertFramework/0.1.0/CommonAlertFramework.podspec.json
  - Log messages:
    - June 30th, 03:09: Push for `CommonAlertFramework 0.1.0' initiated.
    - June 30th, 03:09: Push for `CommonAlertFramework 0.1.0' has been pushed (1.620009634 s).

如果上一步标红的你没有执行的话,会出现如下的错误信息:

$ pod trunk push CommonAlertFramework.podspec 
Updating spec repo `master`

CocoaPods 0.38.0.beta.1 is available.
To update use: `gem install cocoapods --pre`
[!] This is a test version we'd love you to try.

For more information see http://blog.cocoapods.org
and the CHANGELOG for this version http://git.io/BaH8pQ.

Validating podspec
<span style="color:#ff0000;">[!] /usr/bin/git clone https://github.com/*****/CommonAlertFramework.git /var/folders/bq/94b3k1g55lndg97g1bnk58w80000gn/T/d20150630-12006-1apb9xw --single-branch --depth 1 --branch 0.1.0

Cloning into '/var/folders/bq/94b3k1g55lndg97g1bnk58w80000gn/T/d20150630-12006-1apb9xw'...

warning: Could not find remote branch 0.1.0 to clone.

fatal: Remote branch 0.1.0 not found in upstream origin</span>

13、到此,public模式的下的库成功添加。

需要注意的地方总结如下:

  1. summary和description必须填写且description内容比summary长
  2. s.homepage和s.source里面的地址要填写对
  3. 库文件是在步骤2标注的开发区里面
  4. 每次添加新的文件之类操作的话,别忘记执行pod install 或者 pod update
  5. tag设置好之后,要push上去
  6. 每次push之前,如果提示无权或者啥的,就register一下


暂时就这些吧,如果有什么问题,欢迎提出


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"failed to push some refs to"是Git在推送代码到远程仓库时出现的错误消息。它通常发生在有多人协同开发的团队中,可能是因为你在推送代码之前有其他人已经推送了代码,导致你的本地库和远程库发生了冲突。 解决这个问题的方法可以分为以下几步: 1. 首先,你可以尝试使用git pull命令来拉取远程仓库的最新代码。这将合并远程仓库和你的本地仓库的更改。但是,在执行这个命令之前,你需要先提交你的本地更改,否则会出现错误提示要先提交本地更改。 2. 执行git pull命令后,如果有冲突,你需要解决这些冲突。这可以通过手动修改冲突的文件来完成。Git会在冲突的文件中用特殊的标记标识出冲突的部分,你需要根据需要进行修改。 3. 解决冲突后,你可以使用git add命令将修改后的文件添加到暂存区。然后使用git commit命令提交这些更改。 4. 最后,你可以再次尝试使用git push命令将你的更改推送到远程仓库。这次应该不会再出现"failed to push some refs to"的错误消息。 综上所述,你可以通过执行git pull命令来拉取远程仓库的最新代码,并解决可能出现的冲突,然后再次尝试推送你的更改到远程仓库。这样应该能够解决"failed to push some refs to"的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [git push错误failed to push some refs to的解决](https://blog.csdn.net/UUUUUnnn/article/details/125945902)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [git push 报错failed to push some refs to‘xxx](https://blog.csdn.net/weixin_45811256/article/details/125989719)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [error: failed to push some refs to 'https://gitee.com/xiao-long](https://download.csdn.net/download/m0_56760139/87455643)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值