CocoaPods安装和使用

安装cocoapods

sudo gem install cocoapods

用系统默认代理可能很慢,可以用淘宝的RubyGems镜像来代替官方版本,执行以下命令:

$ gem sources -l
$ gem sources --remove https://rubygems.org/
$ gem sources -a https://ruby.taobao.org/
$ gem sources -l

安装成功后,接着执行命令:

pod setup

如果Ruby环境不够新,可能需要更新以下:

sudo gem update --system

使用CocoaPods的第一步,是在当前项目下,新建一个Podfile文件:

$ cd 项目路径
$ touch Podfile

然后利用vim打开Podfile文件编辑,加入你想要使用的类库,格式如下:

platform :ios
pod 'Reachability', '3.1.0'

platform:ios, '6.0'
pod 'SBJson','4.0.2'
pod 'SDWebImage+ExtensionSupport','3.7.1.2'
pod 'AFNetworking', '2.5.0'

确定定三方库版本

pod search AFNetworking

如果是拷贝的别人的项目,或是一个很久没打开过的项目,可能需要先执行一下:

pod update

最后一步,执行命令:

pod install

成功后会提示

Please close any current Xcode sessions and use XXXX.xcworkspace for this project from now on.

关于Podfile文件编辑时,第三方库版本号的各种写法:

pod ‘AFNetworking’      //不显式指定依赖库版本,表示每次都获取最新版本
pod ‘AFNetworking’,  ‘2.0’     //只使用2.0版本
pod ‘AFNetworking’, ‘>2.0′     //使用高于2.0的版本
pod ‘AFNetworking’, ‘>=2.0′     //使用大于或等于2.0的版本
pod ‘AFNetworking’, ‘<2.0′     //使用小于2.0的版本
pod ‘AFNetworking’, ‘<=2.0′     //使用小于或等于2.0的版本
pod ‘AFNetworking’, ‘~>0.1.2′     //使用大于等于0.1.2但小于0.2的版本,相当于>=0.1.2并且<0.2.0
pod ‘AFNetworking’, ‘~>0.1′     //使用大于等于0.1但小于1.0的版本
pod ‘AFNetworking’, ‘~>0′     //高于0的版本,写这个限制和什么都不写是一个效果,都表示使用最新版本

CocoaPod安装过程中常遇问题
问题一

[!] Unable to find a pod with name matching `AFNetworking'

解决方法

pod setup

问题二

[!] CocoaPods was not able to update the `master` repo. If this is an unexpected issue and persists you can inspect it running `pod repo update --verbose`

解决方法
1.可能是网络问题,多试几次
2.

pod repo remove master
pod setup

3.卸载重装cocopad
先删除全局的缓存:

$ sudo rm -fr ~/Library/Caches/CocoaPods/
$ sudo rm -fr ~/.cocoapods/repos/master/
$ sudo rm -fr Pods/

重装

$ sudo gem install cocoapods

Podfile配置问题

[!] Unable to satisfy the following requirements:

- `AFNetworking (~> 2.6.3)` required by `Podfile`

Specs satisfying the `AFNetworking (~> 2.6.3)` dependency were found, but they required a higher minimum deployment target.

在这里插入图片描述

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值