书接上文(CocoaPods / Pod 安装简略步骤),在本地安装了CocoaPods之后,我们就开始配置工程和添加第三方库让pod管理,下面就进行实战操作,让pod配置变的如此简单(标注-红色为我们手动输入,黑色为命令行自己输出):
第一步:验证是否pod安装成功
ZPodsDemo mapboo$ pod --version
0.38.2
第二步:创建工程项目,和平时一样,然后打开终端进入该工程根目录
~ mapboo$ cd /Users/mapboo/Desktop/ZPodsDemo
ZPodsDemo mapboo$ ls
ZPodsDemo ZPodsDemo.xcodeproj
ZPodsDemoTests
第三步:创建pod管理配置文件
ZPodsDemo mapboo$ touch Podfile
ZPodsDemo mapboo$ ls -a
. PodfileZPodsDemoTests
.. ZPodsDemo
.DS_Store ZPodsDemo.xcodeproj
注意:多了Podfile文件在根目录
第四步:搜索需要添加的第三方库JSONKit
ZPodsDemo mapboo$ pod search JSONKit
-> GCJSONKit (1.5.0)
GC‘s fork of a Very High Performance Objective-C JSON Library.
pod ‘GCJSONKit‘, ‘~> 1.5.0‘
- Homepage: https://github.com/gamechanger/JSONKit
- Source: https://github.com/gamechanger/JSONKit.git
- Versions: 1.5.0 [master repo]
-> JSONKit (1.5pre)
A Very High Performance Objective-C JSON Library.
pod ‘JSONKit‘, ‘~> 1.5pre‘
- Homepage: https://github.com/johnezang/JSONKit
- Source: https://github.com/johnezang/JSONKit.git
- Versions: 1.5pre, 1.4 [master repo]
-> JSONKit-NoWarning (1.2)
A Very High Performance Objective-C JSON Library.
pod ‘JSONKit-NoWarning‘, ‘~> 1.2‘
- Homepage: https://github.com/ignazioc/JSONKit-NoWarning
- Source: https://github.com/ignazioc/JSONKit-NoWarning.git
- Versions: 1.2, 1.1 [master repo]
-> SGJsonKit (1.2.4)
Auto-mapping json objects to Objective-C classes
pod ‘SGJsonKit‘, ‘~> 1.2.4‘
- Homepage: http://github.com/dongminkim/SGJsonKit
- Source: https://github.com/dongminkim/SGJsonKit.git
- Versions: 1.2.4, 1.2.3, 1.2.2, 1.2.1, 1.2, 1.1.1, 1.1, 1.0 [master repo]
第五步:打开Podfile文件,可以在终端用vim或直接在项目中右键文本中打开,输入如下代码
platform :ios
pod ‘JSONKit‘, ‘~> 1.5pre’
第六步:开始安装该第三方库
ZPodsDemo mapboo$ pod install --verbose --no-repo-update
Preparing
[!] Unable to load a specification for the plugin `/Library/Ruby/Gems/2.0.0/gems/cocoapods-try-release-fix-0.1.2`
Analyzing dependencies
Inspecting targets to integrate
Using `ARCHS` setting to build architectures of target `Pods`: (``)
Resolving dependencies of `Podfile`
Comparing resolved specification to the sandbox manifest
A JSONKit
Downloading dependencies
-> Installing JSONKit (1.5pre)
> Copying JSONKit from
`/Users/mapboo/Library/Caches/CocoaPods/Pods/Release/JSONKit/1.5pre-efef3` to
`Pods/JSONKit`
- Running pre install hooks
Generating Pods project
- Creating Pods project
- Adding source files to Pods project
- Adding frameworks to Pods project
- Adding libraries to Pods project
- Adding resources to Pods project
- Linking headers
- Installing targets
- Installing target `JSONKit` iOS 4.3
- Installing target `Pods` iOS 4.3
- Running post install hooks
- Writing Xcode project file to `Pods/Pods.xcodeproj`
- Writing Lockfile in `Podfile.lock`
- Writing Manifest in `Pods/Manifest.lock`
Integrating client project
[!] Please close any current Xcode sessions and use `ZPodsDemo.xcworkspace` for this project from now on.
Integrating target `Pods` (`ZPodsDemo.xcodeproj` project)
Adding Build Phase ‘Copy Pods Resources‘ to project.
Adding Build Phase ‘Check Pods Manifest.lock‘ to project.
- Running post install hooks
- cocoapods-stats from
`/Library/Ruby/Gems/2.0.0/gems/cocoapods-stats-0.5.3/lib/cocoapods_plugin.rb`
Sending stats
- JSONKit, 1.5pre
Failed to send stats: SSL_connect returned=1 errno=0 state=SSLv2/v3 read
server hello A: sslv3 alert handshake failure
安装完成后再看项目目录如下:
第六步:配置第三方库路径,源项目就可以引入相对路径头文件
${SRCROOT} recursive
如图配置
前后对比
第七步:更改第三方库
如果有修改、更新或添加第三方库,可以直接打开Podfile文件,例如输入如下:
platform :ios
pod ‘Reachability‘, ‘~> 3.0.0’
然后再次运行命令
ZPodsDemo mapboo$ pod install --verbose --no-repo-update
就等于删除了之前的JSONKit库,新增了Reachability库
第八步:打开项目双击ZPodsDemo.xcworkspace即可开始正常开发;
至此,我们完整的实战操作了一次pod管理第三方库的全部流程,再也不用担心第三方库的更新问题了,大家好,我是Z,下次再见,更多优秀博文,可下载IT面试宝典-博文推荐栏目下阅读。
版权声明:本文为博主原创文章,未经博主允许不得转载。