CocoaPods是一个负责管理iOS项目中第三方开源代码的工具。CocoaPods项目的源码在Github上管理。该项目开始于2011年8月12日,经过一年多的发展,现在已经超过1000次提交,并且持续保持活跃更新。开发iOS项目不可避免地要使用第三方开源库,CocoaPods的出现使得我们可以节省设置和更新第三方开源库的时间。
安装
在安装之前,运行以下命令
gem update --system
可以升级系统当前的ruby版本
安装方式异常简单, Mac下都自带ruby,通过终端(Terminal)使用ruby的gem命令即可下载安装:
$ gem install cocoapods
$ pod setup
gem install cocoapods
命令也可以自动升级当前cocoapods版本
更新使用
$ sudo gem install cocoapods
一旦安装完毕,通过运行
pod setup
命令来设置CocoaPods
Once installed, setup CocoaPods by running the pod setup command. During the setup process, the CocoaPods environment is formed and a .cocoapods directory is created in your home folder. This hidden folder contains all the available pod specifications or pod specs.
A dependency declaration has a lot more configuration options, which can be set in the Podfile. If you want to work with the bleeding edge version of a library, for example, you can replace a pod’s version number with :head as shown below. You can even tell CocoaPods what source to use by specifying the git repository or referring CocoaPods to a local copy of the library. These are more advanced features of CocoaPods.
pod 'AFNetworking', :head
pod 'SVProgressHUD', :git => 'https://github.com/samvermette/SVProgressHUD'
pod 'ViewDeck', :local => '~/Development/Library/ViewDeck'
pod 'DTCoreText', :git => 'https://github.com/Cocoanetics/DTCoreText.git'
With our list of dependencies specified, it is time to continue the setup process. Update the Podfile as shown below and run pod install in the Terminal. Make sure to run this command in the root of your Xcode project where you also created the project’s Podfile.
platform :ios, '6.0'
pod 'ViewDeck', '~> 2.2.2'
pod 'AFNetworking', '~> 1.1.0'
pod 'SVProgressHUD', '~> 0.9.0'
pod 'HockeySDK', '~> 3.0.0'
pod install
使用:
Open Terminal, and navigate to the folder where your project is. Type the following:
touch Podfile
open -e Podfile
TextEdit should open up showing an empty file. You just created the pod file and opened it! Ready to add some content to the empty pod file?
Copy and paste the following lines into the TextEdit window:
platform :ios
pod 'AFNetworking', '0.9.1'
Now, save the file and close TextEdit, going back to terminal. Ready to configure your project?
Issue the following command via Terminal:
pod install
You should see output similar to the following:
Updating spec repo `master'
Installing AFNetworking (0.9.1)
Generating support files
It might also tell you something like this:
[!] From now on use `CocoaPodsExample.xcworkspace'
If you type ls now (or browse the project folder using Finder), you’ll see that CocoaPods created a Pods folder – where it stores all dependencies – and CocoaPodsExample.xcworkspace.
VERY IMPORTANT!
From now on, as the command-line warning mentioned, you must always open the workspace (CocoaPodsExample.xcworkspace) and not the project!
现在,你的所有第三方库都已经下载完成并且设置好了编译参数和依赖,你只需要记住如下2点即可:
使用CocoaPods生成的 .xcworkspace 文件来打开工程,而不是以前的 .xcodeproj 文件。
每次更改了Podfile文件,你需要重新执行一次pod install命令
安装DTCoreText一定要注意Other Linker Flags的属性值
-all_load和-ObjC要满足
分享到:
相关推荐
cocoaPods安装使用指南,包括如何安装,升级及注意事项
cocoapods安装使用具体操作步骤
最简洁的Pod入门,新手的最佳选择,请大牛们指正!
cocoapods的安装和使用详细说明
Cocoapods的安装和使用1 .先升级Gem(可以省略) sudo gem update --system2 .切换cocoapods的数据源 【先删除,再添加,查看】 gem source --remove ...
CocoaPods 是一个用于管理 iOS 项目依赖的开源工具。它允许开发人员轻松地添加、更新和删除第三方库和框架,从而简化了 iOS 开发过程中的依赖管理问题。以下是关于 CocoaPods 安装与使用的 PPT 资源描述。
iOS开发中最常用最有名的类库管理工具之一
CocoaPods
IOS CocoaPods的安装与使用教程
在Mac上面, 快速安装Ruby ,以便iOS项目中使用CocoaPods(通过XCode 管理项目中引入的三方类)。包括RVM的安装、Ruby版本设置、下载和安装CocoaPods、以及cocoaPods的简单使用
每次安装Cocoapods总是会出现一些问题,最近比较闲就整理了一下安装文档,包括一些我遇到的问题和解决方案,有参考网上的一些资源,在此发表记录,也希望能帮到需要的人。
如何安装 Ruby和Ruby Gems 的运行环境,CocoaPods环境安装与使用?
第一步:安装cocoapods sudo gem install cocoapods 要是不成功,执行以下操作 gem sources –remove https://rubygems.org/ gem sources -a http://ruby.taobao.org/ gem sources -l(用来查看是否成功) sudo gem ...
安装ruby环境(使用cocoaPods)的基本步骤
CocoaPods是一个负责管理iOS项目中第三方开源库的工具,开发iOS项目不可避免地要使用第三方开源库。接下来通过本文给大家介绍2016最新CocoaPods安装和错误解决方案,需要的的朋友参考下吧
写一篇文章完整地记录一下自己的CocoaPods安装过程,并收集了一些安装过程常见的错误供大家参考。
这是一个cocoaPods的安装和使用开发文档。