CocoaPods集成到Xcode项目中的步骤

来源:互联网 发布:人工智能计算器 编辑:程序博客网 时间:2024/05/21 06:11
工程目录下载地址:https://github.com/liuhongjun719/CocoaPodsDemo

一、步骤

1、进入工程所在的目录(工程根目录), 执行终端操作:执行命令  cd  CocoaPodsDemo/
2、生成Podfile文件:执行命令 touch Podfile不能写成别的名字,也可以自己在工程根目录里面直接新建
3、打开Podfile文件, 执行命令 open -e Podfile第一次执行这个命令,会有一个空白文件打开,可以先放在一边),内容如下:
Podfile中输入下面内容
platform :ios, '7.0'
pod 'AFNetworking', '~> 3.1.0'
注意
platform那一行,ios三个字母都要小写,而且与前面的冒号之间不能有间隔,后面的版本号也可以不写,但是有些开源库对版本是有要求的,比如要在6.0以上才能运行,遇到这样的开源库就需要写上版本号。
也可以在终端输入上面数据:
(1) 输入终端命令 vim Podfile  显示如下


(2) 用vim打开文件后如如 i 进入插入模式  如下


(3) 编辑完成后按esc退出编辑模式,接着输入:wq保存并退出文件

4、在终端查看第三方库版本,例如执行终端命令:pod search AFNetworking, 信息显示如下:

-> AFNetworking (3.1.0)

   A delightful iOS and OS X networking framework.

   pod 'AFNetworking', '~> 3.1.0'

   - Homepage: https://github.com/AFNetworking/AFNetworking

   - Source:   https://github.com/AFNetworking/AFNetworking.git

   - Versions: 3.1.0, 3.0.4, 3.0.3, 3.0.2, 3.0.1, 3.0.0, 3.0.0-beta.3,

   3.0.0-beta.2, 3.0.0-beta.1, 2.6.3, 2.6.2, 2.6.1, 2.6.0, 2.5.4, 2.5.3, 2.5.2,

   2.5.1, 2.5.0, 2.4.1, 2.4.0, 2.3.1, 2.3.0, 2.2.4, 2.2.3, 2.2.2, 2.2.1, 2.2.0,

   2.1.0, 2.0.3, 2.0.2, 2.0.1, 2.0.0, 2.0.0-RC3, 2.0.0-RC2, 2.0.0-RC1, 1.3.4,

   1.3.3, 1.3.2, 1.3.1, 1.3.0, 1.2.1, 1.2.0, 1.1.0, 1.0.1, 1.0, 1.0RC3, 1.0RC2,

   1.0RC1, 0.10.1, 0.10.0, 0.9.2, 0.9.1, 0.9.0, 0.7.0, 0.5.1 [master repo]

   - Subspecs:

     - AFNetworking/Serialization (3.1.0)

     - AFNetworking/Security (3.1.0)

     - AFNetworking/Reachability (3.1.0)

     - AFNetworking/NSURLSession (3.1.0)

     - AFNetworking/UIKit (3.1.0)



-> AFNetworking+AutoRetry (0.0.5)

   Auto Retries for AFNetworking requests

   pod 'AFNetworking+AutoRetry', '~> 0.0.5'

   - Homepage: https://github.com/shaioz/AFNetworking-AutoRetry

   - Source:   https://github.com/shaioz/AFNetworking-AutoRetry.git

   - Versions: 0.0.5, 0.0.4, 0.0.3, 0.0.2, 0.0.1 [master repo]



-> AFNetworking+Ext (1.2.1)

   AFNetworking的封装, 并提供一个 UIImageView+DYLoading  cache in fileSystem+memory

   pod 'AFNetworking+Ext', '~> 1.2.1'

   - Homepage: https://github.com/junhaiyang/AFNetworkingExt

   - Source:   https://github.com/junhaiyang/AFNetworkingExt.git

   - Versions: 1.2.1, 1.2, 1.1, 1.0, 0.5, 0.4, 0.3 [master repo]

   - Subspecs:

     - AFNetworking+Ext/Base (1.2.1)

     - AFNetworking+Ext/AFCustomRequestOperation (1.2.1)

     - AFNetworking+Ext/AFDownloadRequestOperation (1.2.1)

     - AFNetworking+Ext/AFTextResponseSerializer (1.2.1)

     - AFNetworking+Ext/example (1.2.1)

     - AFNetworking+Ext/UIKit (1.2.1)

     - AFNetworking+Ext/UIKit/UIImageView+DYLoading (1.2.1)



-> AFNetworking+ImageActivityIndicator (1.0.2)

   AFNetworking+ImageActivityIndicator makes it easy to show an activity

   indicator while an image view's image is loading using AFNetworking.

   pod 'AFNetworking+ImageActivityIndicator', '~> 1.0.2'

   - Homepage:

   https://github.com/JRG-Developer/AFNetworking-ImageActivityIndicator

   - Source:  

   https://github.com/JRG-Developer/AFNetworking-ImageActivityIndicator.git

   - Versions: 1.0.2, 1.0.1, 1.0.0 [master repo]



-> AFNetworking+SingleBlock (0.0.1)

   Categories that aggregate the success and failure block in one single

   solution

   pod 'AFNetworking+SingleBlock', '~> 0.0.1'

   - Homepage: https://github.com/acerbetti/AFNetworking-SingleBlock

   - Source:   https://github.com/acerbetti/AFNetworking-SingleBlock.git

   - Versions: 0.0.1 [master repo]



-> AFNetworking+streaming (0.6.2)

   A very quick extension to AFNetworking that adds stream based parsing

   pod 'AFNetworking+streaming', '~> 0.6.2'

   - Homepage: https://github.com/deanWombourne/AFNetworking-streaming

   - Source:   https://github.com/deanWombourne/AFNetworking-streaming.git

   - Versions: 0.6.2, 0.6.1, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1 [master repo]

   - Subspecs:

     - AFNetworking+streaming/Core (0.6.2)

     - AFNetworking+streaming/Json (0.6.2)



-> AFNetworking-BoltsSupport (1.1.0)

   Bolts support for AFNetworking.

   pod 'AFNetworking-BoltsSupport', '~> 1.1.0'

   - Homepage: https://github.com/taka0125/AFNetworking-BoltsSupport

   - Source:   https://github.com/taka0125/AFNetworking-BoltsSupport.git

   - Versions: 1.1.0, 1.0.0 [master repo]



-> AFNetworking-MUResponseSerializer (1.0.1)

   Automatically serialize JSON response to your object model. It also works

   with NSManagedObjects

   pod 'AFNetworking-MUResponseSerializer', '~> 1.0.1'

   - Homepage: https://github.com/Ulianko/AFNetworking-MUResponseSerializer

   - Source:   https://github.com/Ulianko/AFNetworking-MUResponseSerializer.git

   - Versions: 1.0.1, 1.0.0 [master repo]



-> AFNetworking-PromiseKit (0.2.4)

   AFNetworking category for PromiseKit

   pod 'AFNetworking-PromiseKit', '~> 0.2.4'

   - Homepage: https://github.com/cmckni3/AFNetworking-PromiseKit

   - Source:   https://github.com/cmckni3/AFNetworking-PromiseKit.git

   - Versions: 0.2.4, 0.2.3, 0.2.2, 0.2.1, 0.2.0, 0.1.0 [master repo]



-> AFNetworking-RACExtensions (0.1.8)

   AFNetworking-RACExtensions is a delightful extension to the AFNetworking

   classes for iOS and Mac OS X.

   pod 'AFNetworking-RACExtensions', '~> 0.1.8'

   - Homepage: https://github.com/CodaFi/AFNetworking-RACExtensions

   - Source:   https://github.com/CodaFi/AFNetworking-RACExtensions.git

   - Versions: 0.1.8, 0.1.6, 0.1.4, 0.1.2, 0.1.1, 0.0.1 [master repo]



-> AFNetworking-RACRetryExtensions (0.2.0)

   AFNetworking-RACRetryExtensions is an extension to the AFNetworking classes

   for iOS and Mac OS X that adds the auto-retry ability.

   pod 'AFNetworking-RACRetryExtensions', '~> 0.2.0'

   - Homepage: https://github.com/legoless/AFNetworking-RACRetryExtensions

   - Source:   https://github.com/legoless/AFNetworking-RACRetryExtensions.git

   - Versions: 0.2.0, 0.1.2, 0.1.1 [master repo]



-> AFNetworking-ReactiveCocoa (0.0.2)

   Make AFNetworking reactive.

   pod 'AFNetworking-ReactiveCocoa', '~> 0.0.2'

   - Homepage: https://github.com/uasi/AFNetworking-ReactiveCocoa

   - Source:   https://github.com/uasi/AFNetworking-ReactiveCocoa.git

   - Versions: 0.0.2, 0.0.1 [master repo]



-> AFNetworking-Synchronous (0.3.1)

   Synchronous requests for AFNetworking

   pod 'AFNetworking-Synchronous', '~> 0.3.1'

   - Homepage: https://github.com/paulmelnikow/AFNetworking-Synchronous

   - Source:   https://github.com/paulmelnikow/AFNetworking-Synchronous.git

   - Versions: 0.3.1, 0.3.0, 0.2.0, 0.1.0 [master repo]

   - Subspecs:

     - AFNetworking-Synchronous/1.x (0.3.1)

     - AFNetworking-Synchronous/2.x (0.3.1)



-> AFNetworking-Webp (0.2)

   A Webp image response serializer for AFNetworking 2.0

   pod 'AFNetworking-Webp', '~> 0.2'

   - Homepage: https://github.com/brandons/AFNetworking-Webp

   - Source:   https://github.com/brandons/AFNetworking-Webp.git

   - Versions: 0.2, 0.1 [master repo]



-> AFNetworking2-RACExtensions (0.0.1)

   AFNetworking-RACExtensions is a delightful extension to the AFNetworking

   classes for iOS and Mac OS X.

   pod 'AFNetworking2-RACExtensions', '~> 0.0.1'

   - Homepage: https://github.com/knshiro/AFNetworking-RACExtensions

   - Source:   https://github.com/knshiro/AFNetworking-RACExtensions.git

   - Versions: 0.0.1 [master repo]



-> AFNetworkingHelper (0.1.4)

   A short wrapper written over AFNetworking library.

   pod 'AFNetworkingHelper', '~> 0.1.4'

   - Homepage: https://github.com/RainingClouds/AFNetworkingHelper

   - Source:   https://github.com/RainingClouds/AFNetworkingHelper.git

   - Versions: 0.1.4, 0.1.3, 0.1.2, 0.1.1, 0.1.0 [master repo]



-> CollectionUtils-AFNetworking (1.0.2)

   CollectionUtils additions for AFNetworking.

   pod 'CollectionUtils-AFNetworking', '~> 1.0.2'

   - Homepage: https://github.com/kishikawakatsumi/CollectionUtils

   - Source:   https://github.com/kishikawakatsumi/CollectionUtils.git

   - Versions: 1.0.2, 1.0.1, 1.0.0 [master repo]



-> CollectionUtils-AFNetworking-1.3 (1.0.1)

   CollectionUtils additions for AFNetworking 1.3.x.

   pod 'CollectionUtils-AFNetworking-1.3', '~> 1.0.1'

   - Homepage: https://github.com/kishikawakatsumi/CollectionUtils

   - Source:   https://github.com/kishikawakatsumi/CollectionUtils.git

   - Versions: 1.0.1, 1.0.0 [master repo]



-> HYVConfiguratorAFNetworking-Mantle (0.6.3)

   Configurator for using AFNetworking with Mantle

   pod 'HYVConfiguratorAFNetworking-Mantle', '~> 0.6.3'

   - Homepage:

   https://github.com/LilushFess/HYVConfiguratorAFNetworking-Mantle.git

   - Source:  

   https://github.com/LilushFess/HYVConfiguratorAFNetworking-Mantle.git

   - Versions: 0.6.3, 0.6.2, 0.6.1, 0.6, 0.4.1, 0.4, 0.3.1, 0.3.0, 0.2.1, 0.2.0,

   0.1.4, 0.1.3.2, 0.1.3.1, 0.1.3, 0.1.2.2, 0.1.2, 0.1.1.42, 0.1.0 [master repo]



-> Haneke+AFNetworking (0.2.0)

   Haneke extension to use AFNetworking to download images.

   pod 'Haneke+AFNetworking', '~> 0.2.0'

   - Homepage: https://github.com/Haneke/Haneke-AFNetworking

   - Source:   https://github.com/Haneke/Haneke-AFNetworking.git

   - Versions: 0.2.0 [master repo]



-> JJAFNetworking (1.0)

   A Networking Tool used on iOS.

   pod 'JJAFNetworking', '~> 1.0'

   - Homepage: https://github.com/JayJJ/JJAFNetworking

   - Source:   https://github.com/JayJJ/JJAFNetworking.git

   - Versions: 1.0 [master repo]



-> LJAFNetWorking (0.0.1)

   LJAFNetWorking 工具

   pod 'LJAFNetWorking', '~> 0.0.1'

   - Homepage: https://github.com/soft6096/LJAFNetWorking

   - Source:   https://github.com/soft6096/LJAFNetWorking.git

   - Versions: 0.0.1 [master repo]



-> PromiseKit-AFNetworking (0.6.0)

   PromiseKit extensions for AFNetworking

   pod 'PromiseKit-AFNetworking', '~> 0.6.0'

   - Homepage: https://github.com/csotiriou/AFNetworking-PromiseKit/

   - Source:   https://github.com/csotiriou/AFNetworking-PromiseKit.git

   - Versions: 0.6.0, 0.5.1, 0.5.0, 0.1.7, 0.1.6, 0.1.5, 0.1.4, 0.1.3, 0.1.2,

   0.1.1 [master repo]



-> UIImageView_AFNetworking-Blocks (0.1.0)

   UIImageView+AFNetworking with a single completion block for success and

   failure.

   pod 'UIImageView_AFNetworking-Blocks', '~> 0.1.0'

   - Homepage: https://github.com/pixio/UIImageView_AFNetworking-Blocks

   - Source:   https://github.com/pixio/UIImageView_AFNetworking-Blocks.git

   - Versions: 0.1.0 [master repo]



-> XMAFNetworking (1.0.3)

   一个基于AFNetworking 网络请求类库的封装

   pod 'XMAFNetworking', '~> 1.0.3'

   - Homepage: https://github.com/ws00801526/XMAFNetworkingExample

   - Source:   https://github.com/ws00801526/XMAFNetworkingExample.git

   - Versions: 1.0.3, 1.0.2, 1.0.1, 1.0.0 [master repo]

   - Subspecs:

     - XMAFNetworking/Core (1.0.3)

     - XMAFNetworking/Download (1.0.3)

     - XMAFNetworking/Upload (1.0.3)


5、在工程中生成CocoaPodsDemo.xcworkspace文件以及Pods文件夹,AFNetworking就已经下载完成并且设置好了编译参数和依赖,返回信息如下。执行终端命令:pod install  (要先执行pod install,再执行pod update)  (如果想执行的快一些,可以使用终端命令:pod install --verbose --no-repo-update )

Updating local specs repositories


CocoaPods 1.0.0.beta.6 is available.

To update use: `gem install cocoapods --pre`

[!] This is a test version we'd love you to try.


For more information see http://blog.cocoapods.org

and the CHANGELOG for this version http://git.io/BaH8pQ.


Analyzing dependencies

Downloading dependencies

Installing AFNetworking (3.1.0)

Generating Pods project

Integrating client project


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

Sending stats

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

 

pod installed.


6、继续添加第三方库时的操作,只需要在终端执行命令,pod update

例如加入第三方库GCJSONKit,

(1) 首先执行终端命令 po search GCJSONKit,显示数据如下:

-> 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]



-> MDKJSONKit (1.0.0)

   MDKJSONKit is JSONKit compatible iOS 9.0

   pod 'MDKJSONKit', '~> 1.0.0'

   - Homepage: https://www.movalys.org

   - Source:   https://github.com/MovalysMDK/mdk-ios-jsonkit.git

   - Versions: 1.0.0 [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]

(2) 从终端进入含有Podfile文件的文件夹中,执行终端命令 open -e Podfile
(3) 将上面的红色部分pod 'GCJSONKit', '~> 1.5.0'拷贝到Podfile文件中,并保存,如下:
(4) 更新Podfile文件,执行终端命令: pod update, 此时反馈信息如下:

Update all pods

Updating local specs repositories


CocoaPods 1.0.0.beta.6 is available.

To update use: `gem install cocoapods --pre`

[!] This is a test version we'd love you to try.


For more information see http://blog.cocoapods.org

and the CHANGELOG for this version http://git.io/BaH8pQ.


Analyzing dependencies

Downloading dependencies

Using AFNetworking (3.1.0)

Installing GCJSONKit (1.5.0)

Generating Pods project

Integrating client project

Sending stats

Pod installation complete! There are 2 dependencies from the Podfile and 2

total pods installed.


[!] 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.

(5) 此时工程中的Pods文件夹中会显示GCJSONKit文件


7、在项目中import第三方库
 注意:使用Pods配置的项目,在#import头文件时,需要使用"<>"    如: #import

二、注意

1.从此以后需要使用Cocoapods生成的CocoaPodsDemo.xcworkspace文件来打开工程,而不是使用以前的CocoaPodsDemo.xcodeproj文件

2.每次更改了Podfile文件,都需要重新执行一次pod update命令

ps:当执行pod install之后,除了Podfile,还会生成一个名为Podfile.lock的文件,它会锁定当前各依赖库的版本,之后即使多次执行pod install也不会更改版本,只有执行pod update才会改变Podfile.lock.在多人协作的时候,这样可以防止第三方库升级时候造成大家各自的第三方库版本不一致。所以在提交版本的时候不能把它落下,也不要添加到.gitignore中。Podfile.lock和Podfile文件如下




三、补充

如何查看所安装的第三方库的版本信息

(1)终端命令: cd Pods 显示如下



(2)终端命令:open -e Manifest.lock  显示信息如下

PODS:

  - AFNetworking (3.1.0):

    - AFNetworking/NSURLSession (= 3.1.0)

    - AFNetworking/Reachability (= 3.1.0)

    - AFNetworking/Security (= 3.1.0)

    - AFNetworking/Serialization (= 3.1.0)

    - AFNetworking/UIKit (= 3.1.0)

  - AFNetworking/NSURLSession (3.1.0):

    - AFNetworking/Reachability

    - AFNetworking/Security

    - AFNetworking/Serialization

  - AFNetworking/Reachability (3.1.0)

  - AFNetworking/Security (3.1.0)

  - AFNetworking/Serialization (3.1.0)

  - AFNetworking/UIKit (3.1.0):

    - AFNetworking/NSURLSession

  - GCJSONKit (1.5.0)

  - MBProgressHUD (0.9.2)

  - MBProgressHUD-WR (1.0.0):

    - MBProgressHUD (~> 0.9.1)


DEPENDENCIES:

  - AFNetworking (~> 3.1.0)

  - GCJSONKit (~> 1.5.0)

  - MBProgressHUD-WR (~> 1.0.0)


SPEC CHECKSUMS:

  AFNetworking: 5e0e199f73d8626b11e79750991f5d173d1f8b67

  GCJSONKit: 8ad0067945efd217af8e610fa09ca0d02283b36b

  MBProgressHUD: 1569cf7ace17a8bac47aabfbb8580a49690386d1

  MBProgressHUD-WR: acef59fa0bb0c0d76c841e2f3e79c2fd802a07c4


COCOAPODS: 0.39.0


四、删除Pods中的第三方库

1. 输入终端命令: open -e Podfile  如删除pod 'AFNetworking', '~> 3.1.0'
2.再重新输入终端命令: pod install  输出信息如下,红色部分Removing AFNetworking

Updating local specs repositories


CocoaPods 1.0.0.beta.6 is available.

To update use: `gem install cocoapods --pre`

[!] This is a test version we'd love you to try.


For more information see http://blog.cocoapods.org

and the CHANGELOG for this version http://git.io/BaH8pQ.


Analyzing dependencies

Removing AFNetworking

Downloading dependencies

Using GCJSONKit (1.5.0)

Using MBProgressHUD (0.9.2)

Using MBProgressHUD-WR (1.0.0)

Generating Pods project

Integrating client project

Sending stats

Pod installation complete! There are 2 dependencies from the Podfile and 3 total

pods installed.


[!] 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.




0 0