一直關(guān)注IOS開(kāi)發(fā)多年,開(kāi)始今天的教程。
現(xiàn)在的我的配置如下:
– Mac OSX 10.11.0
– Git (ie: GitHub for Mac Desktop)
– XCode 7.3.1
– CocoaPods 1.0.0
解決CocoaPods版本過(guò)低或升級(jí)問(wèn)題
進(jìn)入終端輸入指令
$ pod install
#[!] The version of CocoaPods used to generate the lockfile (0.39.0) is higher than the version of the current executable (0.35.0). Incompatibility issues may arise.
告知版本太低了烘豌,執(zhí)行更新cocoapod版本指令
$ gem update cocoapod
#Nothing to update
檢查淘寶服務(wù)器地址為https協(xié)議,如果是http請(qǐng)改成https
$ gem sources -r http://ruby.taobao.org/
#http://ruby.taobao.org/ removed from sources
$ gem sources -a https://ruby.taobao.org/
#https://ruby.taobao.org/ added to sources
使用sudo來(lái)執(zhí)行操作看彼,因?yàn)椴僮魇窍到y(tǒng)文件夾加上權(quán)限操作
$ sudo gem update --system
#Updating rubygems-update
#Fetching: rubygems-update-2.5.1.gem (100%)
#Successfully installed rubygems-update-2.5.1
#Parsing documentation for rubygems-update-2.5.1
再執(zhí)行部署cocoapod指令廊佩,時(shí)間會(huì)慢,因?yàn)樾枰獔?zhí)行把所有的cocoapods repo全部download到本地的操作靖榕,應(yīng)該有100M+吧标锄。
$ pod setup
#Setting up CocoaPods master repo
#Setup completed
#[!] CocoaPods was not able to update the `master` repo. If this is an unexpected issue and persists you can inspect it running `pod repo update --verbose`
??注意到最后一句,我們?cè)诮K端繼續(xù)敲打指令更新repo茁计,耐心等待??..
$ pod repo update --verbose
#Updating spec repo `master`
#$ /usr/bin/git pull --ff-only
#From https://github.com/CocoaPods/Specs
#a0baa68..9a14a05? master? ? -> origin/master
error: Your local changes to the following files would be overwritten by merge:
#CocoaPods-version.yml
#Specs/1PasswordExtension/1.0.0/1PasswordExtension.podspec.json
#Specs/1PasswordExtension/1.0.1/1PasswordExtension.podspec.json
#Specs/AKUTestKit/1.1.2/AKUTestKit.podspec.json
#Specs/ALCore
#Aborting
#Updating a5c6b67..9a14a05
#[!] CocoaPods was not able to update the `master` repo. If this is an unexpected issue and persists you can inspect it running `pod repo update --verbose`
這部分問(wèn)題解決了料皇,現(xiàn)在可以使用pod install 和 pod search xx 進(jìn)行項(xiàng)目pod管理了。
過(guò)度到git版本管理
為了解決大量git指令的晦澀星压,使用GitHub for Mac Desktop解決大部分git版本管理的困難践剂。
創(chuàng)建一個(gè)代碼倉(cāng)庫(kù),在這個(gè)之前需要一個(gè)賬號(hào)和密碼娜膘,填寫(xiě)必要的倉(cāng)庫(kù)地址和相關(guān)信息就一直Next下去吧逊脯。
完成創(chuàng)建倉(cāng)庫(kù)后迫不及待把自己的測(cè)試工程成發(fā)布到git上面,這里我用GitHub for Mac Desktop軟件竣贪,可以很輕松完成版本的發(fā)布工作军洼,這里就不一一贅述了。
配置podspec文件
最后一步配置podspec文件演怎,這個(gè)文件描述你要pod trunk到CocoaPods的工程匕争,??CocoaPods 需要0.33版本以上的,用 pod --version 查看爷耀,如果版本低甘桑,需要更新,之前有介紹更新方法畏纲。
pod trunk register orta@cocoapods.org 'Orta Therox' --description='macbook air'
你注冊(cè)的時(shí)候需要替換郵箱和名字扇住,然后順利的話(huà)你會(huì)收到一份郵件,需要點(diǎn)擊驗(yàn)證盗胀。通過(guò)下面指令能驗(yàn)證你的注冊(cè)信息艘蹋。
pod trunk me?
OK到此為為止我們已經(jīng)在Cocoapods關(guān)聯(lián)相關(guān)信息,cd 進(jìn)入已經(jīng)上傳到GitHub項(xiàng)目的目錄下票灰,執(zhí)行下面指令創(chuàng)建podspec文件女阀。
pod spec create HZWebViewController
會(huì)在當(dāng)前目錄下生成 HZWebViewController.podspec 文件宅荤,然后我們用文本編輯該文檔。
# Be sure to run `pod lib lint HZWebViewController.podspec' to ensure this is a
# valid spec before submitting.
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
Pod::Spec.new do |s|
s.name? ? ? ? = "HZWebViewController"
s.version? ? ? = "0.0.1"
s.summary ? = "play with cocoaPods"
s.description? = <<-DESC
I play with cocoaPods where this one project
DESC
s.homepage ?= "https://github.com/githubAmount/HZWebViewController"
s.license ?= "MIT"
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "suger" => "gjw_2007@163.com" }
s.platform = :ios, '7.0'
s.source ?= { :git =>"https://github.com/githubAmount/HZWebViewController.git", :tag => s.version.to_s }
s.source_files? = "MyTestCocoaPods/MyObject/**/*.{h,m}"
s.public_header_files = "MyTestCocoaPods/MyObject/**/*.h"
s.requires_arc = true
s.frameworks = "UIKit", "Foundation"
#s.dependency 'Masonry', '~> 0.6.3'
end
終于編寫(xiě)完成文件后浸策,立馬在終端輸入下列指令本地驗(yàn)證
$pod lib lint
解決Error和Warming冯键,比如 " 寫(xiě)成了 “ 等等諸如此類(lèi)問(wèn)題。
驗(yàn)證遠(yuǎn)程庫(kù)是否有效庸汗。
$pod spec lint
看到輸出如下內(nèi)容就成功了
HZWebViewController.podspec passed validation.
驗(yàn)證完畢后現(xiàn)在就要把自己工程push到cocoapods倉(cāng)庫(kù)里惫确,執(zhí)行下面的代碼
$pod trunk push
在push 的時(shí)候會(huì)報(bào)錯(cuò)如下圖所示:
???那就百度如何給自己的倉(cāng)庫(kù)打tag并且提交置Github上,關(guān)鍵代碼如下:
$git tag -a 創(chuàng)建版本 -m "v0.0.1"
#git tag -a TagName -m "vTagNumber"
$git push --tags
好吧問(wèn)題又來(lái)了枉昏,此時(shí)終端提示輸入Github的賬號(hào)和密碼陈肛,我怎么輸入都驗(yàn)證過(guò)不了,一直報(bào)不存在的帳戶(hù)和密碼(排除賬號(hào)密碼錯(cuò)誤的情況)兄裂。我懷疑Github不再支持輸入賬號(hào)密碼訪(fǎng)問(wèn)遠(yuǎn)程倉(cāng)庫(kù)的方法句旱,萬(wàn)念俱灰啊~
繼續(xù)百度中??...
還有另外一種方法不用每次訪(fǎng)問(wèn)遠(yuǎn)程倉(cāng)庫(kù)輸入Github賬號(hào)和密碼的方法,這就是要配置SSH晰奖,通過(guò)本地生成一串RSA訪(fǎng)問(wèn)谈撒。打開(kāi)終端輸入以下指令
$ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
#Creates a new ssh key, using the provided email as a label
#Generating public/private rsa key pair.
下面有個(gè)三個(gè)提示建議用三個(gè)回車(chē)對(duì)應(yīng)
Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
此時(shí)在你的/Users/you/.ssh路徑下會(huì)生成一串RSA,你需要把你私鑰加入你的筆記本SSH Session上畅涂,執(zhí)行下面指令
#start the ssh-agent in the background
$eval "$(ssh-agent -s)"
Agent pid 59566
$ ssh-add ~/.ssh/id_rsa
把公鑰加入Github的帳戶(hù)設(shè)置中,用txt打開(kāi)id_rsa.pub文件把里面的內(nèi)容Copy港华,復(fù)制到下面這個(gè)地方
保存后在終端輸入以下指令
$ssh -T git@github.com
#Attempts to ssh to GitHub
會(huì)有下面的提示,全部yes吧午衰,驗(yàn)證你的ssh
The authenticity of host 'github.com (192.30.252.1)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)?
The authenticity of host 'github.com (192.30.252.1)' can't be established.
RSA key fingerprint is nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)?
最后驗(yàn)證成后會(huì)提示以下:
Hi username! You've successfully authenticated, but GitHub does not
provide shell access.
OK立宜,現(xiàn)在我們重新回到打標(biāo)簽的步驟,重新吧標(biāo)簽打到我們遠(yuǎn)程倉(cāng)庫(kù)上臊岸,此時(shí)應(yīng)該順利打上0.0.1標(biāo)簽了~
打完標(biāo)簽記得使用Github的GUI打出一份分支記得也是0.0.1版本橙数。
此時(shí)再回到pod trunk push 步驟重新執(zhí)行一遍。
如果你人品比較好的話(huà)帅戒,此時(shí)你的項(xiàng)目可以順利發(fā)布到cocoapods上面了灯帮,記得到這里來(lái)認(rèn)領(lǐng)你的項(xiàng)目哦https://trunk.cocoapods.org/claims/new
此時(shí)你再使用pod search yourProject 應(yīng)該是能搜索使用了啊~~~
如果有任何問(wèn)題請(qǐng)郵我,地址gjw_2007@163.com逻住,thx.
(完)