CocoaPods安装和使用

来源:互联网 发布:淘宝产品没有展现 编辑:程序博客网 时间:2024/06/06 08:43

安装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 :iospod '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.0pod ‘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 masterpod 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
原创粉丝点击