这次继打包自定义ZYZAlertView为.a 和framework静态库之后,尝试提交代码到cocoapods 便于代码的三方管理,如下就是提交过程。
1.由于之前我已经上传代码到GitHub上了,所以我直接拷贝下来了。
1.1打开Xcode点击工具栏Xcode ->preferences ->Accounts 左下角加号
1.2将你的Github 代码URL地址放到Address 输入电脑用户名密码(代码地址 GitHub clone or download 下面就是)
add 完成后 选中左边列表你的iOS项目 点击工具栏Source Control checkout 就可以了
2.这样你本地就有你的demo了,如果你要新加什么.h .m文件 将文件拖到git目录下,再提交下
cd “你的demo git 的文件夹path”
git add -A
git commit -m “first commit for version 1.0.0”
git push origin master
同时 打tag(这一步不能少,后面.podspec文件会用到该版本号)
git tag '1.0.0' (有人'v1.0.0' 这里一个坑后面说)
git push --tags
3.以上是代码前期准备工作,接下来就是提交代码到cocoapods(你得已经安装了cocoapods )
pod --version (1.2.0我的)
3.1 注册主干线(邮箱用户名,最好和github 一致(不过我的不是,也没问题))
pod trunk register 159XXXXXXX@sina.cn Asia --verbose
提示我
LoadError - cannot load such file -- openssl
/usr/local/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- openssl (LoadError)
[!] Oh no, an error occurred.
Search for existing GitHub issues similar to yours:
https://github.com/CocoaPods/CocoaPods/search?q=cannot+load+such+file+--+openssl&type=Issues
If none exists, create a ticket, with the template displayed above, on:
https://github.com/CocoaPods/CocoaPods/issues/new
点击相关链接进去查看,于是我检查openssl 是否ok
ruby -ropenssl -e "puts :OK”
/usr/local/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- openssl (LoadError)
3.2 openssl 不行那就重装openssl吧
上面那个GitHub链接里,提示用RVM装openssl
我没有装rvm 于是装 rvm
curl -L https://get.rvm.io | bash -s stable
提示成功如下
Installation of RVM in /Users/zhifu360/.rvm/ is almost complete:
* To start using RVM you need to run `source /Users/zhifu360/.rvm/scripts/rvm`
in all your open shell windows, in rare cases you need to reopen all shell windows.
于是按指示
source /Users/zhifu360/.rvm/scripts/rvm
rvm -v (版本 1.29.1)
提示# No rvm rubies installed yet. Try 'rvm help install’.
于是我又 rvm install ruby
完成后 ruby -ropenssl -e "puts :OK”
ok(结果)
openssl终于安装上了(现在我再发现其实我早安装了homebrew,可以homebrew install openssl试试不用这么一堆)
3.3 再来注册pod trunk register 15XXXXXXm0@sina.cn yazhouzhang --verbose
结果提示:
/usr/local/lib/ruby/2.4.0/rubygems.rb:270:in `find_spec_for_exe': can't find gem cocoapods (>= 0.a) (Gem::GemNotFoundException)
我勒个去,问题又来了,问百度吧,说要更新gem 好吧(其实是找不到cocoapod,之前安装有,更新下ruby不见,呵呵)
更行gem:sudo gem update —system 输入密码
gem -v(2.6.12)
依然错误:/usr/local/lib/ruby/2.4.0/rubygems.rb:270:in `find_spec_for_exe': can't find gem cocoapods (>= 0.a) (Gem::GemNotFoundException)(没cocoapods肯定吗,看懂语句很重要,不懂搞半天在)
那就安装cocoapods:sudo gem install cocoapods
3.4再来注册:pod trunk register XXXXXXX yazhouzhang —verbose
[!] Please verify the session by clicking the link in the verification email that has been sent to 15926389954m0@sina.cn
ad-shzhangyazhou:ZYZAlertViewGit AsiaZhang$ pod trunk me
- Name: Asia
- Email: 159XXXXXXX@sina.cn
- Since: May 4th, 19:20
- Pods: None
- Sessions:
- May 4th, 19:20 - September 9th, 19:26. IP: 180.173.185.10
邮箱点击链接认证,omygod终于注册成功
4.填写pod spec内容这一步至关重要 错一个都不行记得一定标点不要用中文 做完这些之后一般会打个tag标记一下(要是不会请面壁)请务必参考我的spec或则github上面大神的自己写容易出错若是要编辑这个文件我用的是sublime text或者是 vim(建议不要用里面不要的东西太多了)
贴上我的
Pod::Spec.new do |s|
s.name = "ZYZAlertView"
s.version = "0.0.1"
s.summary = "Asia design of ZYZAlertView."
s.description = <<-DESC
design by my self Asia Zhang. The frame work has two style. One is like UIAlertView,another like Android.s toast.
DESC
s.homepage = "https://github.com/yazhouZhang/ZYZAlertView"
s.license = "MIT"
s.author = { "yazhouZhang" => "15XXXXX@qq.com" }
s.ios.deployment_target = "8.0"
s.source = { :git => "https://github.com/yazhouZhang/ZYZAlertView.git", :tag => "0.0.1" }
s.source_files = "ZYZAlertView/**/*.{h,m}"
s.requires_arc = true
end
5.完成后校验下pod.spec
5.1pod spec lint ZYZAlertView.podspec
错误
-> ZYZAlertView (1.0.0)
- WARN | source: The version should be included in the Git tag.
- ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://github.com/yazhouZhang/ZYZAlertView.git /var/folders/tg/kkt5ymz564vg4vm_4yrly1vw0000gn/T/d20170505-31896-1wvjqzy --template= --single-branch --depth 1 --branch 0.0.1
Cloning into '/var/folders/tg/kkt5ymz564vg4vm_4yrly1vw0000gn/T/d20170505-31896-1wvjqzy'...
warning: Could not find remote branch 0.0.1 to clone.
fatal: Remote branch 0.0.1 not found in upstream origin
) during validation.
这里弄很久,其实意思是说 不能够找到远程的0.0.1这个分支或者tag
5.2好吧我打tag
git tag ‘v0.0.1'
git push —tags
5.3依然这个问题,好吧,那我打分支
git branch
master (当前一个分支)
git branch 0.0.1
查看git branch
0.0.1
* master(两个了)
5.4再来pod spec lint ZYZAlertView.podspec
还是
-> ZYZAlertView (0.0.1)
- ERROR | [iOS] unknown: Encountered an unknown error ([!] /usr/bin/git clone https://github.com/yazhouZhang/ZYZAlertView.git /var/folders/tg/kkt5ymz564vg4vm_4yrly1vw0000gn/T/d20170505-32253-dq5d5m --template= --single-branch --depth 1 --branch 0.0.1
Cloning into '/var/folders/tg/kkt5ymz564vg4vm_4yrly1vw0000gn/T/d20170505-32253-dq5d5m'...
warning: Could not find remote branch 0.0.1 to clone.
fatal: Remote branch 0.0.1 not found in upstream origin
) during validation.
Analyzed 1 podspec.
5.5直到某一刻我看到了 0.0.1没错不是v0.0.1网上都是v0.0.1还说别写 0.0.1 tag
结果
git tag ‘0.0.1'
git push —tags
pod spec lint ZYZAlertView.podspec-> ZYZAlertView (0.0.1)
- WARN | [iOS] license: Unable to find a license file
- WARN | xcodebuild: ZYZAlertView/ZYZAlertView/ZYZAlertView-ToastView/ZYZToastView.m:163:40: warning: 'sizeWithFont:constrainedToSize:lineBreakMode:' is deprecated: first deprecated in iOS 7.0 - Use -boundingRectWithSize:options:attributes:context: [-Wdeprecated-declarations]
- NOTE | xcodebuild: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator10.3.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIStringDrawing.h:70:1: note: 'sizeWithFont:constrainedToSize:lineBreakMode:' has been explicitly marked deprecated here
Analyzed 1 podspec.
两个警告成功了,我呵呵了
5.6最后忽略警告
pod trunk push ZYZAlertView.podspec —allow-warnings
Updating spec repo `master` 等待最后提示--------------------------------------------------------------------------------
Congrats
ZYZAlertView (0.0.1) successfully published
May 4th, 21:23
https://cocoapods.org/pods/ZYZAlertView
Tell your friends!
———————————————————————————————————————
恭喜你成功了(高兴太早了)
6.来搜搜我的库
pod search ZYZAlertView
厉害了
Creating search index for spec repo 'master'.. Done!
[!] Unable to find a pod with name, author, summary, or description matching `ZYZAlertView`
弄了半天找不到,问问度娘
1执行pod setup
其实在你安装CocoaPods执行pod install时,系统会默认操作pod setup,然而由于中国强大的墙可能会pod setup不成功。这时就需要手动执行pod setup指令,如下:
终端输入:pod setup
会出现Setting up CocoaPods master repo,稍等几十秒,最底下会输出Setup completed。说明执行pod setup成功。
如果pod search操作还是搜索失败,如下:
终端输入:pod search AFNetworking
输出:Unable to find a pod with name, author, summary, or descriptionmatching 'AFNetworking'这时就需要继续下面的步骤了。
2删除~/Library/Caches/CocoaPods目录下的search_index.json文件
pod setup成功后,依然不能pod search,是因为之前你执行pod search生成了search_index.json,此时需要删掉。
终端输入:rm ~/Library/Caches/CocoaPods/search_index.json
删除成功后,再执行pod search。
3执行pod search
终端输入:pod search afnetworking(不区分大小写)
输出:Creating search index for spec repo 'master'.. Done!,稍等片刻······就会出现所有带有afnetworking字段的类库。
拿走,不谢!
按照这个 pod search ZYZAlertView
Creating search index for spec repo 'master'.. Done!
(END)
-> ZYZAlertView (0.0.1)
Asia design of ZYZAlertView.
pod 'ZYZAlertView', '~> 0.0.1'
- Homepage: https://github.com/yazhouZhang/ZYZAlertView
- Source: https://github.com/yazhouZhang/ZYZAlertView.git
- Versions: 0.0.1 [master repo]
成功解决