pod卸载:
第一步:
which pod
第二步:
sudo rm -rf <path>
CocoaPods是一个负责管理iOS项目中第三方开源代码的工具。
1.CocoaPods的安装
方法一:
需要用到ruby,Mac系统自带ruby,但如果不是最新的系统,最好更新一下。
ruby的软件源rubygems.org被墙了,所以先换一下源,命令行下依次执行3条命令
$ gem source -r https://rubygems.org/
$ gem source -a https://ruby.taobao.org
$ gem sources -l
然后升级gem
$ sudo gem update --system
完了就开始安装CocoaPods
$ sudo gem install cocoapods
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/fuzzy_match
出现这个错误就执行这个命令:sudo gem install -n /usr/local/bin cocoapods --pre
如果不出现就不执行
然后执行pod setup进行安装
方法二:
也可以用这个方法更换镜像源:
gitcafe和oschina都是国内的服务器,可以用它们CocoaPods索引库的镜像:
$ pod repo remove master
$ pod repo add master https://gitcafe.com/akuandev/Specs.git
[!] /usr/bin/git clone https://gitcafe.com/akuandev/Specs.git master
xcrun: error: active developer path ("/Applications/Xcode 3.app/Contents/Developer") does not exist, use `xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools (or see `man xcode-select`)
出现这个错误就执行这个命令:sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
如果不出现就不执行
$ pod repo update
如果想用oschina的镜像也可以把第二条命令 换成 http://git.oschina.net/akuandev/Specs.git 即可
第二条命令执行的时候会比较耗时,这个时候要去把整个specs仓库clone一下,下载到 ~/.cocoapods里;
2.CocoaPods的使用
(1)在终端shell中cd 来到你要管理的项目,
添加第三方库
搜索一个开源库
$ pod search AFNetworking
在工程目录里建一个Podfile文件
$ vim Podfile
内容按这个格式来
platform :ios,’7.1’
pod 'RegexKitLite', '~> 4.0'
pod 'ASIHTTPRequest', '~> 1.8.2'
pod 'SDWebImage', '~> 3.7.1'
pod 'FMDB', '~> 2.3'
运行:pod install --verbose --no-repo-update 你的工程就多了个xworkspace文件夹,以后用这个打开工程
3.CocoaPods的使用心得
(1)最近使用CocoaPods来添加第三方类库,无论是执行pod install还是pod update都卡在了Analyzing dependencies不动 原因在于当执行以上两个命令的时候会升级CocoaPods的spec仓库,加一个参数可以省略这一步,命令如下: pod install --verbose --no-repo-update
$ pod install只会按照Podfile的要求来请求类库,如果类库版本号有变化,那么将获取失败。但是 $ pod update会更新所有的类库,获取最新版本的类库。每次用$ pod update就行。
(2)安装一个xcode插件管理工具 http://alcatraz.io,执行curl -fsSL https://raw.github.com/supermarin/Alcatraz/master/Scripts/install.sh | sh 完了打开xcode->window->package manger 搜cocoapods安装,方便操作。xcode -> product -> creatprofile 建立profile文件 输入platform :ios,’7.1’
pod 'RegexKitLite', '~> 4.0'
pod 'ASIHTTPRequest', '~> 1.8.2'
pod 'SDWebImage', '~> 3.7.1'
pod 'FMDB', '~> 2.3'
然后在终端 cd 到工程所在目录 执行pod install --verbose --no-repo-update 你的工程就多了个xworkspace文件夹,以后用这个打开工程
(3)工程在模拟器上编译报错,不支持i386,Cocoapods确实还不支持64位模拟器,解决办法:
http://stackoverflow.com/questions/19213782/undefined-symbols-for-architecture-arm64
其实就2条,1.build active architecture only 在debug的时候设置成YES,不要在release的时候用模拟器 2.other linker flags 加一个 $(inherited)
(4)用到svn,git多人协作的话,Pods/这个文件夹不要上传,.../Pods/Pods.xcodeproj ...Pods/Target Support Files/这些每次编译都会改动从而引起合并代码的时候冲突
更多坑可以看wiki,例如 https://github.com/CocoaPods/CocoaPods/issues/2190
其他坑各位可以补充。。。
(1)卡在Updating local specs repositories
pod install 被墙了,请大家换成pod install --verbose --no-repo-update
(2)出现这种警告
Your Podfile has had smart quotes sanitised. To avoid issues in the future, you should not use TextEdit for editing it. If you are not using TextEdit, you should turn off smart quotes in your editor of choice.
解决办法:不要使用文本编辑去编辑Podfile,使用Xcode编辑,或者使用终端敲命令去编辑。或者输入格式错误,没输入运行版本:$platform:ios, ‘9.0‘
(3)使用cocoapods导入第三方类库后头文件没有代码提示?
解决办法: 选择Target -> Build Settings 菜单,找到\”User Header Search Paths\”设置项,新增一个值"${SRCROOT}",并且选择\”Recursive\”
(4)在别人电脑出错 提示找不到该文件
设置Project -> Info -> Configurations ,把里面的Debug和Release的None改为对应的pods就OK了。