CocoaPods使用详情及版本未更新安装报错

it2022-05-05  71

CocoaPods使用详情

一、概要

iOS开发时,项目中会引用许多第三方库,CocoaPods(https://github.com/CocoaPods/CocoaPods)可以用来方便的统一管理这些第三方库。

 

二、安装

由于网上的教程基本都大同小异,但细节之处还不是很完善,所以借机会在这里补充下:

注:要使用CocoaPods,那就要下载安装它,而下载安装CocoaPods需要Ruby环境

 

1、Ruby环境搭建

当前安装环境为Mac mini 10.8.5。Mac  OS本身自带Ruby,但还是更新一下保险,因为我第一次安装在没有更新Ruby的情况下就失败了。

a 查看下当前ruby版本:打开终端输入 ruby -v(确实安装了,不过用这个版本接下来工作失败了,所以更新下ruby)

1 ritekiMac-mini:PodTest lucky$ ruby -v 2 ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0] 3 ritekiMac-mini:PodTest lucky$

 

b 更新ruby

 

终端输入如下命令(把Ruby镜像指向taobao,避免被墙,你懂得)

gem sources --remove https://rubygems.org/ gem sources -a https://ruby.taobao.org/ gem sources -l  (用来检查使用替换镜像位置成功)

1 ritekiMac-mini:~ lucky$ gem sources --remove https://rubygems.org/ 2 https://rubygems.org/ removed from sources 3 ritekiMac-mini:~ lucky$ gem sources -a https://ruby.taobao.org/ 4 https://ruby.taobao.org/ added to sources 5 ritekiMac-mini:~ lucky$ gem sources -l 6 *** CURRENT SOURCES ***

 

2、下载安装CocoaPods

终端输入:sudo gem install cocoapods 

 

1 ritekiMac-mini:~ lucky$ sudo gem install cocoapods 2 3 CHANGELOG: 4 5 ## 0.32.1 6 7 ##### Bug Fixes 8 9 * Fixed the Podfile `default_subspec` attribute in nested subspecs. 10 [Fabio Pelosin][irrationalfab] 11 \ [#2050](https://github.com/CocoaPods/CocoaPods/issues/2050) 12 13 14 Successfully installed cocoapods-0.32.1 15 Installing ri documentation for cocoapods-0.32.1 16 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rdoc/rdoc.rb:280: warning: conflicting chdir during another chdir block 17 /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rdoc/rdoc.rb:287: warning: conflicting chdir during another chdir block 18 Done installing documentation for cocoapods after 10 seconds 19 1 gem installed

 

 

这样就下载安装好了CocoaPods

 

 

3、使用CocoaPods

a  新建一个项目,名字PodTest

 

b  终端中,cd到项目总目录(注意:包含PodTest文件夹、PodTest.xcodeproj、PodTestTest的那个总目录)

  1 cd /Users/lucky/Desktop/PodTest  

 

c  建立Podfile(配置文件)

接着上一步,终端输入 vim Podfile

 

键盘输入 i,进入编辑模式,输入

platform :ios, '7.0' pod 'MBProgressHUD', '~> 0.8'

 

然后按Esc,并且输入“ :”号进入vim命令模式,然后在冒号后边输入wq

 

 注意:键盘输入 :后,才能输入wq。回车后发现PodTest项目总目录中多一个Podfile文件

 

激动人心的时刻到了:确定终端cd到项目总目录,然后输入 pod install,等待一会,大约3分钟。

 

查看项目根目录:

 

注意:现在打开项目不是点击 PodTest.xodeproj了,而是点击 PodTest.xcworkspace

 

打开项目后看到项目结构并且测试一下:

运行结果:

 

补充:

1、CocoaPods的基本安装及使用都详细的说明了,但还有一些补充,当需要同时导入多个第三方时候怎么办 ?

这就需要修改Podfile了,就是用vim编辑的那个保存在项目根目录中的文件,修改完了Podfile文件,需要重新执行一次pod install命令。

例如:

 

platform :ios

pod 'JSONKit',       '~> 1.4'

pod 'AFNetworking',  '~> 2.0'

 

2、CocoaPods可以查找你想要的第三方库

终端输入命令:pod search UI

疯了了,我怎么查找这么大众的关键字,好多库~~

然后重新编辑Podfile文件,按照之前的步骤,把更多的库都导入项目!

 

本博客盗窃自阿福的博客,地址:http://blog.csdn.net/lizhongfu2013/article/details/26384029

 

============================我是分割线==================================

2015-11-18更新

淘宝已经关闭HTTP协议的景象服务,改为HTTPS协议。

淘宝ruby地址:https://ruby.taobao.org/  本文转载自:http://blog.csdn.net/showhilllee/article/details/38398119

 CocoaPods版本更新了之后本地未更新,安装第三方库报错如下

一、问题

[!] The dependency `AFNetworking (~> 2.0)` is not used in any concrete target.(CocoaPods 报错)

二、解决

ex:

1 The dependency `` is not used in any concrete target 2 The dependency `AFNetworking ` is not used in any concrete target CocoaPods再遇困难,前几天电脑重装了系统,所有的开发工具就都装了最新的,当我用CocoaPods的时候,出了一个提示,大概就是我的版本不是 last version,然后给你提示了一个命令,直接复制即可,就是下面这个:   sudo gem install cocoapods --pre

安装cocoapods的预览版本,就会更新下来新的1.0.0.beta.2版本,如下所示:

1 Successfully installed cocoapods-1.0.0.beta.2 2 Parsing documentation for cocoapods-1.0.0.beta.2

很高兴啊,更新了新的版本,然而pod install就出错了,悲了个剧!出错如下:

1 Updating local specs repositories 2 Analyzing dependencies 3 [!] The dependency `FMDB (~> 2.3)` is not used in any concrete target. 4 The dependency `SDWebImage (~> 3.6)` is not used in any concrete target. 5 The dependency `AFNetworking (~> 2.3.0)` is not used in any concrete target. 6 The dependency `DACircularProgress (~> 2.2.0)` is not used in any concrete target. 7 The dependency `MBProgressHUD (~> 0.8)` is not used in any concrete target. 8 The dependency `PSTCollectionView (~> 1.2.1)` is not used in any concrete target. 9 The dependency `HPGrowingTextView (~> 1.1)` is not used in any concrete target. 10 The dependency `ProtocolBuffers (= 1.9.3)` is not used in any concrete target. 11 The dependency `leveldb-library (~> 1.18.1)` is not used in any concrete target. 12 The dependency `SCLAlertView-Objective-C (~> 0.7.5)` is not used in any concrete target. 13 The dependency `MWPhotoBrowser (~> 1.4.1)` is not used in any concrete target. 14 The dependency `MMMarkdown (~> 0.5)` is not used in any concrete target. 15 The dependency `MJExtension (~> 2.5.16)` is not used in any concrete target. 16 The dependency `MJRefresh (~> 2.4.12)` is not used in any concrete target. 17 The dependency `Masonry (~> 0.6.3)` is not used in any concrete target.

我用的三方库比较多,挺长的,出这个错是告诉我们我们所用的库没有指定target,它不知道用在哪里,所以就给报错了,然后我去了cocoapods的官网看了下,cocoapods官网地址

 

官网是这样给推荐的: 在创建Podfile的时候,用这种格式使用,

1 platform :ios, '8.0' 2 #use_frameworks!个别需要用到它,比如reactiveCocoa 3 4 target 'MyApp' do 5 pod 'AFNetworking', '~> 2.6' 6 pod 'ORStackView', '~> 3.0' 7 pod 'SwiftyJSON', '~> 2.3' 8 end 里面的 MyApp 记得替换为自己攻城里面的target。这样就基本OK了,执行pod install / pod update 就都可以了。(use_frameworks! 这个是个别需要的,这里修改一下,可以把我上面的代码中的这一行【删除】)

下面是另外一种写法,

platform :ios, '8.0' #use_frameworks!个别需要用到它,比如reactiveCocoa def pods pod 'AFNetworking', '~> 2.6' pod 'ORStackView', '~> 3.0' pod 'SwiftyJSON', '~> 2.3' end target 'MyApp' do pods end

有疑问的给我评论或者邮件,每天都会看一下 kamy_shi@163.com

 本文转载自:http://blog.csdn.net/sjl_leaf/article/details/50506057

 

转载于:https://www.cnblogs.com/yipingios/p/5710998.html


最新回复(0)