如何使用CocoaPods管理第三方库

IOS 第三方管理库管理 CocoaPods
越来越多的SVN管理,越来越多的工程文件,我不能总是那么一个一个的把第三方库拖进去,我厌倦了拖拽和配置,我找到了替代方法--CocoaPods
英文好的可以直接读一下我参考的网页 http://www.raywenderlich.com/12139/introduction-to-cocoapods
不嫌我唠叨 我就自己慢慢敲
第一步:安装
一般在安装CocoaPods之前是要先配置Ruby环境的,但是如果你已经安装了xcode你就可以直接安装了,不需要配置Ruby环境了,因为可能xcode安装的时候已经配置好了。安装的时候可能需要更新Ruby版本信息就好了
CocoaPods是跑在Ruby的软件,安装可能需要几分钟,打开你的终端输入:
sudo gem install cocoapods(这个有时候需要等很久,如果想快点就用下面补充的办法)
补充一下:最近在给新机子安装时 发现 sudo gem install cocoapods 没有反应,看来又是被墙了,可以用淘宝的ruby镜像
在终端敲入
$ gem sources --remove https://rubygems.org/

等有反应后再敲入 $ gem sources -a http://ruby.taobao.org/

然后测试下是真的可以了么,敲入
$ gem sources -l
*** CURRENT SOURCES *** http://ruby.taobao.org/

恩 好了 继续之前的安装步骤 sudo gem install cocoaPods~~ 就可以了

如果成功 会有一个 Successfully installed cocoaPods的提示 ,

有时候会出现xcode版本提示,可以从appStore上更新xcode.可能遇到下面的问题
Mac AppStore下载失败.解决办法:
我进终端输入defaults write com.apple.appstore ShowDebugMenu -bool true就好了

然后再输入前面说的安装命令安装,这时候可能会遇到这样的问题:
lanou$ sudo gem install cocoapods
Password:
Building native extensions. This could take a while...
[!] You are using the prebuilt binary version of the xcodeproj gem.

CHANGELOG:

## 0.29.0
[CocoaPods](https://github.com/CocoaPods/CocoaPods/compare/0.28.0...0.29.0)
• [CocoaPods-core](https://github.com/CocoaPods/Core/compare/0.28.0...0.29.0)
• [cocoapods-downloader](https://github.com/CocoaPods/cocoapods-downloader/compare/0.2.0...0.3.0)

###### Breaking

* The command `podfile_info` is now a plugin offered by CocoaPods.
\ As a result, the command has been removed from CocoaPods.
[Joshua Kalpin](https://github.com/Kapin)
\ [#1589](https://github.com/CocoaPods/CocoaPods/issues/1589)

* JSON has been adopted as the format to store specifications. As a result
the `pod ipc spec` command returns a JSON representation and the YAML
specifications are not supported anymore. JSON specifications adopt the
`.podspec.json` extension.
[Fabio Pelosin](https://github.com/irrationalfab)
\ [#1568](https://github.com/CocoaPods/CocoaPods/pull/1568)

###### Enhancements

* Introduced `pod try` the easiest way to test the example project of a pod.
[Fabio Pelosin](https://github.com/irrationalfab)
[#1568](https://github.com/CocoaPods/CocoaPods/pull/1568)

* Pod headers are now provided to the user target as a system
header. This means that any warnings in a Pod's code will show
under its target in Xcode's build navigator, and never under the
user target.
[Swizzlr](https://github.com/swizzlr)
\ [#1596](https://github.com/CocoaPods/CocoaPods/pull/1596)

* Support LZMA2 compressed tarballs in the downloader.
[Kyle Fuller](https://github.com/kylef)
[cocoapods-downloader#5](https://github.com/CocoaPods/cocoapods-downloader/pull/5)

* Add Bazaar support for installing directly from a repo.
[Fred McCann](https://github.com/fmccann)
\ [#1632](https://github.com/CocoaPods/CocoaPods/pull/1632)

* The `pod search <query>` command now supports regular expressions
for the query parameter when searching using the option `--full`.
[Florian Hanke](https://github.com/floere)
\ [#1643](https://github.com/CocoaPods/CocoaPods/pull/1643)

* Pod lib lint now accepts multiple podspecs in the same folder.
[kra Larivain/OpenTable](https://github.com/opentable)
\ [#1635](https://github.com/CocoaPods/CocoaPods/pull/1635)

* The `pod push` command will now silently test the upcoming CocoaPods trunk
service. The service is only tested when pushing to the master repo and the
test doesn't affect the normal workflow.
[Fabio Pelosin](https://github.com/irrationalfab)

* The `pod search <query>` command now supports searching on cocoapods.org
when searching using the option `--web`. Options `--ios` and `--osx` are
fully supported.
\ [Florian Hanke](https://github.com/floere)
[#1643](https://github.com/CocoaPods/CocoaPods/pull/1682)

* The `pod search <query>` command now supports multiword queries when using
the `--web` option.
[Florian Hanke](https://github.com/floere)
[#1643](https://github.com/CocoaPods/CocoaPods/pull/1682)

###### Bug Fixes

* Fixed a bug which resulted in `pod lib lint` not being able to find the
headers.
[Fabio Pelosin](https://github.com/irrationalfab)
[#1566](https://github.com/CocoaPods/CocoaPods/issues/1566)

* Fixed the developer frameworks search paths so that
`$(SDKROOT)/Developer/Library/Frameworks` is used for iOS and
`$(DEVELOPER_LIBRARY_DIR)/Frameworks` is used for OS X.
\ [Kevin Wales](https://github.com/kwales)
[#1562](https://github.com/CocoaPods/CocoaPods/pull/1562)

* When updating the pod repos, repositories with unreachable remotes
are now ignored. This fixes an issue with certain private repositories.
[Joshua Kalpin](https://github.com/Kapin)
\ [#1595](https://github.com/CocoaPods/CocoaPods/pull/1595)
[#1571](https://github.com/CocoaPods/CocoaPods/issues/1571)

* The linter will now display an error if a Pod's name contains whitespace.
[Joshua Kalpin](https://github.com/Kapin)
[Core#39](https://github.com/CocoaPods/Core/pull/39)
\ [#1610](https://github.com/CocoaPods/CocoaPods/issues/1610)

* Having the silent flag enabled in the config will no longer cause issues
with `pod search`. In addition, the flag `--silent` is no longer supported
for the command.
\ [Joshua Kalpin](https://github.com/Kapin)
[#1627](https://github.com/CocoaPods/CocoaPods/pull/1627)

* The linter will now display an error if a framework ends with `.framework`
(i.e. `QuartzCore.framework`).
[Joshua Kalpin](https://github.com/Kapin)
[#1331](https://github.com/CocoaPods/CocoaPods/issues/1336)
\ [Core#45](https://github.com/CocoaPods/Core/pull/45)

* The linter will now display an error if a library ends with `.a` or `.dylib`
(i.e. `z.dylib`). It will also display an error if it begins with `lib`
(i.e. `libxml`).
[Joshua Kalpin](https://github.com/Kapin)
[Core#44](https://github.com/CocoaPods/Core/issues/44)

* The ARCHS build setting can come back as an array when more than one
architecture is specified.
[Carson McDonald](https://github.com/carsonmcdonald)
[#1628](https://github.com/CocoaPods/CocoaPods/issues/1628)

* Fixed all issues caused by `/tmp` being a symlink to `/private/tmp`.
This affected mostly `pod lib lint`, causing it to fail when the
Pod used `prefix_header_*` or when the pod headers imported headers
using the namespaced syntax (e.g. `#import <MyPod/Header.h>`).
[kra Larivain/OpenTable](https://github.com/opentable)
\ [#1514](https://github.com/CocoaPods/CocoaPods/pull/1514)

* Fixed an incorrect path being used in the example app Podfile generated by
`pod lib create`.
[Eloy Durán](https://github.com/alloy)
[cocoapods-try#5](https://github.com/CocoaPods/cocoapods-try/issues/5)


Successfully installed i18n-0.6.9
Successfully installed multi_json-1.8.4
Successfully installed activesupport-3.2.16
Successfully installed nap-0.6.0
Successfully installed json_pure-1.8.1
Successfully installed fuzzy_match-2.0.4
Successfully installed cocoapods-core-0.29.0
Successfully installed claide-0.4.0
Successfully installed cocoapods-downloader-0.3.0
Successfully installed rake-10.1.1
Successfully installed colored-1.2
Successfully installed xcodeproj-0.14.1
Successfully installed cocoapods-try-release-fix-0.1.1
Successfully installed escape-0.0.4
Successfully installed open4-1.3.0
Successfully installed cocoapods-0.29.0
16 gems installed
Installing ri documentation for i18n-0.6.9...
Installing ri documentation for multi_json-1.8.4...
Installing ri documentation for activesupport-3.2.16...

unrecognized option `--encoding'

For help on options, try 'rdoc --help'

使用gem –v 查看Ruby版本信息,如果版本很低(2.0.0以下)
那么
解决办法:sudo gem update –system 更新Ruby的版本。
好你的Ruby升级完了,可以重复之前的步骤了。


然后输入
pod setup

第二步:创建一个 Podfile 文件
继续在你的终端操作,先使用 cd 操作 进入你的项目目录例如 cd ~/desktop/HelloWord
在这个目录下创建文件
touch Podfile 然后回车继续输入 open -e Podfile 这时将直接打开一个空的文件先在这打开着不要管一会会处理的
第三步:搂一搂 搜索库
现在就需要找到你要的第三方库了,在终端里输入(以查找Reachability为例)
pod search Reachability
 终端会有和这个搜索结果相近的选项(示例如下)
-> KSReachability (1.3)
A better iOS & Mac reachability for a modern age.
- Homepage: https://github.com/kstenerud/KSReachability
- Source: https://github.com/kstenerud/KSReachability.git
- Versions: 1.3, 1.1, 1.0, 0.0.1 [master repo]
-> NPReachability (0.1.0)
Reachability without the suck.
- Homepage: https://github.com/Abizern/NPReachability
- Source: https://github.com/Abizern/NPReachability.git
- Versions: 0.1.0 [master repo]
-> Reachability (3.1.0)
ARC and GCD Compatible Reachability Class for iOS and OS X. Drop in
replacement for Apple Reachability.
- Homepage: https://github.com/tonymillion/Reachability
- Source: https://github.com/tonymillion/Reachability.git
- Versions: 3.1.0, 3.0.0, 2.0.5 [master repo]
第四步:在刚才打开的空白Podfile中加入你想要的,如
platform :ios (这表示应用平台) pod 'Reachability', '3.1.0' (库的名称 库的版本号)
(如果是多个就继续罗列即可):
platform :ios
pod 'JSONKit','1.4'
pod 'Reachability','3.0.0'
第五步:将这个写入数据的 Podfile保存后关闭
第六步:在终端输入
pod install
然后终端会有显示 示例:
[!] From now on use `name.xcworkspace'.
最后:是的 就像你看到的,你打开工程需要双击 .xcworkspace 这个工程,而不是之前的xcodeproj!!
 
OK 就这样了
最近使用时发现 FMDB找不到,一看版本号 pod --version 0.16.4  好老的版本,然后升级下
就是重新装一下   sudo gem install cocoapods   等操作完成 重新显示一下版本号 0.19.1   OK FMDB也有了~
 
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值