iOS技术分享iOS开发iOS学习笔记

cocoapods的使用(一)--终端指令

2016-09-06  本文已影响153人  上善若水jf

新建一个工程cocoapodsTest

1、在终端中输入cd,将cocoapodsTest工程直接拖到终端中,如下:

cd /Users/admin/Desktop/cocoapodsTest

2、当前目录下,利用vim创建Podfile,在终端中输入:

 vim Podfile

3、按 i 或 a ,进入插入模式,输入以下内容:

platform :ios, ‘7.0’

target ‘cocoapodsTest’ do      //注意:target ‘工程名称’ do

pod 'AFNetworking', '~> 3.1.0'

end

对上面4行文字的解释:

platform :ios, ‘7.0’ ,表示当前AFNetworking支持的iOS最低版本是iOS 7.0

target ‘cocoapodsTest’ do,当前的目标工程

pod 'AFNetworking', '~> 3.1.0',表示需要下载的AFNetworking版本是3.1.0

end ,表示结束

4、输入完毕后,按【ESC】返回命令行模式,:(冒号)进入末行模式,输入,wq保存命令并退出vim

5、这时你会发现工程目录中,出现一个名为Podfile的文件,而且文件内容就是刚刚输入的内容。

(注意,Podfile文件应该和工程文件cocoapodsTest.xcodeproj在同一个目录下)

6、利用CocoaPods下载AFNetworking类库了,在终端中的当前工程目录下,运行以下命令:

 pod install

创建cocoapodsTest.xcworkspace成功时,终端提示如下:

Analyzing dependencies

Downloading dependencies

Installing AFNetworking (3.1.0)

Generating Pods project

Integrating client project

[!] Please close any current Xcode sessions and use `cocoapodsTest.xcworkspace` for this project from now on.

Sending stats

Pod installation complete! There is 1 dependency from the Podfile and 1 total

pod installed.

同时发现在cocoapodsTest文件下,增加了cocoapodsTest.xcworkspace文件,此时说明创建cocoapodsTest.xcworkspace已经成功了。

7、特别注意

    target ‘cocoapodsTest’ do为必须输入,注意:target ‘工程名称’ do,最新版本的cocoapods使用变化,否则无法生成 .xcworkspace文件,一直提示安装报错。

报错:

[!] Invalid `Podfile` file: syntax error, unexpected keyword_end, expecting end-of-input.

#  from /Users/admin/Desktop/test15/Podfile:6

#  -------------------------------------------

#

>  end

#  -------------------------------------------

[!] Your Podfile has had smart quotes sanitised. 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.

上一篇下一篇

猜你喜欢

热点阅读