CocoaPods工具安装

简介

三方库管理工具,很方便,开发自己的APP绝佳的辅助工具

安装介绍

  1. 本人安装时系统版本 10.12.6

  2. 安装 CocoaPods之前,要先确保电脑本地是否有 Ruby环境,因为CocoaPods运行于 Ruby之上,默认情况下,Mac 是自带了 Ruby 环境的,可以通过命令行 ruby -v查看当前Ruby的版本。

执行命令:

zhouzhoujiedeMacBook-Pro:~ jimy$ ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin1
  1. 直接命令行安装CocoaPods,会有如下错误

执行命令:

zhouzhoujiedeMacBook-Pro:~ jimy$ sudo gem install cocoapods
ERROR:  While executing gem ... (OpenSSL::SSL::SSLError)
hostname "http://rubygems-china.oss.aliyuncs.com"  does not match the server 
certificate
  1. 把镜像源改成阿里云的

执行命令:

  • 查看当前镜像
gem sources -l
  • 移除当前镜像
gem sources --remove https://rubygems.org/
  • 替换成阿里云
zhouzhoujiedeMacBook-Pro:~ jimy$ gem sources -a http://rubygems-
china.oss.aliyuncs.com
  1. 安装,需要耐心等待

执行命令:

zhouzhoujiedeMacBook-Pro:~ jimy$ sudo gem install cocoapods

简单使用

  1. 正常创建IOS Swift APP ,名称Test
  2. 打开终端,使用 cd 命令 进入项目Test根目录

执行命令:

zhouzhoujiedeMacBook-Pro:~ jimy$ cd /Users/zhouzhoujie/Documents/project/Test
  1. 生成 Podfile(三方框架的注册文件)

执行命令:

zhouzhoujiedeMacBook-Pro:~ jimy$ pod init
zhouzhoujiedeMacBook-Pro:Test jimy$ ls
Des            Podfile.lock        Test.xcodeproj
Desstatic      Pods            Test.xcworkspace
Podfile            Test
  1. 寻找三方框架,例如寻找"Moya"

执行命令:

zhouzhoujiedeMacBook-Pro:Test jimy$ pod search Moya
  1. 找不到"Moya",你的CocoaPods的本地缓存三方库列表需要更新了

执行命令:

zhouzhoujiedeMacBook-Pro:Test jimy$ pod update
  1. 修改Podfile,将"Moya"安装进入Test

Podfile修改如下

platform :ios, '9.0'
use_frameworks!

def shared_pods
pod 'Moya', '3.2.0'
end

target ‘Test' do
shared_pods
end

7.将"Moya"安装进入Test项目

进入项目根目录,执行命令:

zhouzhoujiedeMacBook-Pro:Test jimy$ pod install
Analyzing dependencies
Downloading dependencies
Using Moya (8.0.5)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod >installed.

[!] Smart quotes were detected and ignored in your Podfile. To avoid issues in the >future, you should not use TextEdit for editing it. If you are not using TextEdit, you >should turn off smart quotes in your editor of choice.
zhouzhoujiedeMacBook-Pro:Test jimy$ 

参考地址,Where 抄 come from

[地址] (http://blog.csdn.net/ylgwhyh/article/details/50542688)

你可能感兴趣的:(CocoaPods工具安装)