CocoaPods
1.安装
- $ sudo gem install cocoapods
- $ pod setup
//出现问题 install 没反应
- $ gem sources --remove https://rubygems.org/
- //等有反应之后再敲入以下命令
- $ gem sources -a http://ruby.taobao.org/
//验证是否替换成功
- $ gem sources -l
//验证结果
- *** CURRENT SOURCES ***
- http://ruby.taobao.org/
//升级gem
- $ sudo gem update --system
③安装完成后,执行pod setup命令时报错:
- /Users/wangzz/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:298:in `to_specs': Could not find 'cocoapods' (>= 0) among 6 total gem(s) (Gem::LoadError)
- from /Users/wangzz/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:309:in `to_spec'
- from /Users/wangzz/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_gem.rb:53:in `gem'
- from /Users/wangzz/.rvm/rubies/ruby-1.9.3-p448/bin/pod:22:in `<main>'
这就是路径设置的问题,可以通过执行:
- $ rvm use ruby-1.9.3-p448
3、升级CocoaPods
升级很简单,再次执行安装命令即可:
- $ sudo gem install cocoapods
需要注意的是,如果安装的时候使用了sudo,升级的时候一样需要使用该关键字,不然升级完了以后又会出现路径不匹配问题。
1、创建Podfile
- $ cd /Users/wangzz/Desktop/CocoaPodsTest
- $ touch Podfile
2、编辑Podfile
- platform :ios
- pod 'Reachability', '~> 3.0.0'
- pod 'SBJson', '~> 4.0.0'
- platform :ios, '7.0'
- pod 'AFNetworking', '~> 2.0'
vi Podfile 打开文件
输入i 开始编辑模式
esc +shift +: 打开输入框
wq 保存并退出
3、执行导入命令
$pod install 执行下载命令
//下载完成
- Analyzing dependencies
- Downloading dependencies
- Installing AFNetworking (2.1.0)
- Installing JSONKit (1.5pre)
- Installing Reachability (3.0.0)
- Generating Pods project
- Integrating client project
- [!] From now on use `CocoaPodsTest.xcworkspace`.
pod setup 报CocoaPods was not able to update the `master` repo 错误解决办法
先删除全局的缓存:
$ sudo rm -fr ~/Library/Caches/CocoaPods/
$ sudo rm -fr ~/.cocoapods/repos/master/
还不行的话就把当前 Pods 目录清空:
$ sudo rm -fr Pods/
// 再执行
$ sudo gem install cocoapods
$ pod setup
- Unable to find a specification for `xxxxx (~> 1.x.x)` depended upon by Podfile.
只需要把当前Pod的目录清理一下就行了。在终端执行以下命令:
- pod repo remove master
- pod setup
setup成功后执行install或update即可。