CocoaPods安装

来源:互联网 发布:淘宝供销平台对接 编辑:程序博客网 时间:2024/06/06 01:02

https://cocoapods.org/

CocoaPods是什么?

CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. It has over 39 thousand libraries and is used in over 2.8 million apps. CocoaPods can help you scale your projects elegantly.

安装

sudo gem install cocoapods

等待完成之后,执行如下命令:

pod setup

等待完成。

搜索库

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: https://github.com/shaioz/AFNetworking-AutoRetry     - 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+RetryPolicy (1.0.4)   AFNetworking+RetryPolicy is an objective-c category that adds the ability to   set the retry logic for requests made with AFNetworking.   pod 'AFNetworking+RetryPolicy', '~> 1.0.4'   - Homepage: https://github.com/kubatruhlar/AFNetworking-RetryPolicy   - Source:   https://github.com/kubatruhlar/AFNetworking-RetryPolicy.git   - Versions: 1.0.4, 1.0.3, 1.0.2, 1.0.1, 1.0.0 [master repo]-> AFNetworking+RX (3.1.0.18)   AFNetworking+RX is a simple ext of AFNetworking   pod 'AFNetworking+RX', '~> 3.1.0.18':

直接按”q”就退出去了。

在工程中创建一个Podfile文件

1、打开命令行,进入项目目录:

cd desktop/CocoaPodsDemo

2、创建Podfile文件
Tip: CocoaPods provides a pod init command to create a Podfile with smart defaults. You should use it.

pod init

默认文件内容:

# Uncomment the next line to define a global platform for your project# platform :ios, '9.0'target 'CocoaPodsDemo' do  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks  # use_frameworks!  # Pods for CocoaPodsDemo  target 'CocoaPodsDemoTests' do    inherit! :search_paths    # Pods for testing  end  target 'CocoaPodsDemoUITests' do    inherit! :search_paths    # Pods for testing  endend

修改后:

# Uncomment the next line to define a global platform for your project# platform :ios, '9.0'target 'CocoaPodsDemo' do  # Uncomment the next line if you're using Swift or would like to use dynamic frameworks  # use_frameworks!  # Pods for CocoaPodsDemo  pod 'AFNetworking', '~> 3.1.0'  target 'CocoaPodsDemoTests' do    inherit! :search_paths    # Pods for testing  end  target 'CocoaPodsDemoUITests' do    inherit! :search_paths    # Pods for testing  endend

安装

pod install

安装过程:

fwwdeMacBook-Air:CocoaPodsDemo fww$ pod installAnalyzing dependenciesDownloading dependenciesInstalling AFNetworking (3.1.0)Generating Pods projectIntegrating client project[!] Please close any current Xcode sessions and use `CocoaPodsDemo.xcworkspace` for this project from now on.