一直关注IOS开发多年,开始今天的教程。
现在的我的配置如下:
– Mac OSX 10.11.0
– Git (ie: GitHub for Mac Desktop)
– XCode 7.3.1
– CocoaPods 1.0.0
解决CocoaPods版本过低或升级问题
进入终端输入指令
$ 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.
告知版本太低了,执行更新cocoapod版本指令
$ gem update cocoapod
#Nothing to update
检查淘宝服务器地址为https协议,如果是http请改成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来执行操作,因为操作是系统文件夹加上权限操作
$ 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
再执行部署cocoapod指令,时间会慢,因为需要执行把所有的cocoapods repo全部download到本地的操作,应该有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`
⚠️注意到最后一句,我们在终端继续敲打指令更新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`
这部分问题解决了,现在可以使用pod install 和 pod search xx 进行项目pod管理了。
过度到git版本管理
为了解决大量git指令的晦涩,使用GitHub for Mac Desktop解决大部分git版本管理的困难。
创建一个代码仓库,在这个之前需要一个账号和密码,填写必要的仓库地址和相关信息就一直Next下去吧。
完成创建仓库后迫不及待把自己的测试工程成发布到git上面,这里我用GitHub for Mac Desktop软件,可以很轻松完成版本的发布工作,这里就不一一赘述了。
配置podspec文件
最后一步配置podspec文件,这个文件描述你要pod trunk到CocoaPods的工程,⚠️CocoaPods 需要0.33版本以上的,用 pod --version 查看,如果版本低,需要更新,之前有介绍更新方法。
pod trunk register orta@cocoapods.org 'Orta Therox' --description='macbook air'
你注册的时候需要替换邮箱和名字,然后顺利的话你会收到一份邮件,需要点击验证。通过下面指令能验证你的注册信息。
pod trunk me
OK到此为为止我们已经在Cocoapods关联相关信息,cd 进入已经上传到GitHub项目的目录下,执行下面指令创建podspec文件。
pod spec create HZWebViewController
会在当前目录下生成 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
终于编写完成文件后,立马在终端输入下列指令本地验证
$pod lib lint
解决Error和Warming,比如 " 写成了 “ 等等诸如此类问题。
验证远程库是否有效。
$pod spec lint
看到输出如下内容就成功了
HZWebViewController.podspec passed validation.
验证完毕后现在就要把自己工程push到cocoapods仓库里,执行下面的代码
$pod trunk push
在push 的时候会报错如下图所示:
🏷️那就百度如何给自己的仓库打tag并且提交置Github上,关键代码如下:
$git tag -a 创建版本 -m "v0.0.1"
#git tag -a TagName -m "vTagNumber"
$git push --tags
好吧问题又来了,此时终端提示输入Github的账号和密码,我怎么输入都验证过不了,一直报不存在的帐户和密码(排除账号密码错误的情况)。我怀疑Github不再支持输入账号密码访问远程仓库的方法,万念俱灰啊~
继续百度中⌛️...
还有另外一种方法不用每次访问远程仓库输入Github账号和密码的方法,这就是要配置SSH,通过本地生成一串RSA访问。打开终端输入以下指令
$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.
下面有个三个提示建议用三个回车对应
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]
此时在你的/Users/you/.ssh路径下会生成一串RSA,你需要把你私钥加入你的笔记本SSH Session上,执行下面指令
#start the ssh-agent in the background
$eval "$(ssh-agent -s)"
Agent pid 59566
$ ssh-add ~/.ssh/id_rsa
把公钥加入Github的帐户设置中,用txt打开id_rsa.pub文件把里面的内容Copy,复制到下面这个地方
保存后在终端输入以下指令
$ssh -T git@github.com
#Attempts to ssh to GitHub
会有下面的提示,全部yes吧,验证你的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)?
最后验证成后会提示以下:
Hi username! You've successfully authenticated, but GitHub does not
provide shell access.
OK,现在我们重新回到打标签的步骤,重新吧标签打到我们远程仓库上,此时应该顺利打上0.0.1标签了~
打完标签记得使用Github的GUI打出一份分支记得也是0.0.1版本。
此时再回到pod trunk push 步骤重新执行一遍。
如果你人品比较好的话,此时你的项目可以顺利发布到cocoapods上面了,记得到这里来认领你的项目哦https://trunk.cocoapods.org/claims/new
此时你再使用pod search yourProject 应该是能搜索使用了啊~~~
如果有任何问题请邮我,地址gjw_2007@163.com,thx.
(完)