這次繼打包自定義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 [email protected] 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 [email protected] 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 [email protected]
ad-shzhangyazhou:ZYZAlertViewGit AsiaZhang$ pod trunk me
- Name: Asia
- Email: [email protected]
- 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" => "[email protected]" }
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]
成功解決