我对CocoaPods的使用
CocoaPods 是 iOS 常用的著名的类库管理工具,使用 Xcode 的时候用 CocoaPods 来管理第三方框架很方便
补充CocoaPods更新
sudo gem install -n /usr/local/bin cocoapods –pre
安装步骤
1.添加源
$ sudo gem sources -a https://ruby.taobao.org/
2.删除源
$ sudo gem sources -r https://rubygems.org/
3.验证新源是否替换成功
$ gem sources -l
gem 的服务器在国外,因此国内想安装 CocoaPods 需要翻墙,惊恐, 但是大笑.国内的淘宝已经做了贡献 https://ruby.taobao.org 这是一个完整 rubygems.org 镜像,频率为15分钟一次。我们需要镜像的可以快速的访问.
code4app 上就写成了 http. 记住了是 https
4.安装 CocoaPods
$ sudo gem install cocoapods --pre
$ pod setup
注意:苹果系统升级 OS X EL Capitan后安装改为:
$ sudo gem install -n /usr/local/bin cocoa pods
$ pod setup
添加第三方框架步骤
1.打开终端 输入 $ cd 进入工程名
输入 $ touch Podfile 将Podfile文件拖入Xcode ,并输入
platform :ios, '8.0'
target 'xxxDemo' do
pod 'AFNetworking'
pod 'SDWebImage'
end
2.输入$ pod install
如果太慢可以尝试: $ pod install --verbose --no-repo-update
gem 的常用命令如下
查看gem源
$ gem sources –l
gem自身升级
$ sudo gem update --system
查看版本
$ gem --version
清除过期的gem
$ sudo gem cleanup
安装包
$ sudo gem install cocoa pods
删除包
$ gem uninstall cocoa pods
更新包
$ sudo gem update
列出本地安装的包
$ gem list
pod的常用命令
创建默认的 Podfile
$ pod init
第一次使用安装框架
$ pod install
安装框架,不更新本地索引,速度快
$ pod install --no-repo-update
今后升级、添加、删除框架,或者框架不好用都使用这个命令
$ pod update
更新框架,不更新本地索引,速度快
$ pod update --no-repo-update
搜索框架
$ pod search XXX
帮助
$ pod --help
以下部分非本人整理,来自简书
可能遇到的错误提示及解决方法:
Error 1:
Error fetching http://ruby.taobao.org/:
bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)
解决方案:把安装流程中 $ gem sources -a http://ruby.taobao.org/
改为:$ gem sources -a https://ruby.taobao.org/
Error 2:
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/pod
解决方案:苹果系统升级 OS X EL Capitan 后会出现的插件错误,将安装流程 安装 CocoaPods 的 sudo gem install cocoapods
改为 sudo gem install -n /usr/local/bin cocoapods
Error 3:
[!] Unable to satisfy the following requirements:
-
AFNetworking (~> 2.3.1)
required byPodfile
Specs satisfying theAFNetworking (~> 2.3.1)
dependency were found, but they required a higher minimum deployment target.
解决方案:Podfile 文件 中 platform:ios, ‘8.0’ 后边的 8.0 是平台版本号 ,一定要加上
Error4:
―――――――――― MARKDOWN TEMPLATE ――――――――――
Report
-
What did you do?
-
What did you expect to happen?
-
What happened instead?
Stack
CocoaPods : 0.29.0
Ruby : ruby 2.0.0p247 (2013-06-27 revision 41674) [universal.x86_64-darwin13]
RubyGems : 2.1.11
Host : Mac OS X 10.9.2 (13C64)
Xcode : 5.1 (5B130a)
Ruby lib dir : /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib
Repositories : master - https://github.com/CocoaPods/Specs.git @ bd6736d07b16c98ab7a1dae04697cae002f25a9b
Podfile
platform :ios,'8.0'
pod 'MBProgressHUD', '~> 0.8'
Error
Psych::SyntaxError - (/Users/MAXJ/.cocoapods/repos/master/CocoaPods-version.yml): mapping values are not allowed in this context at line 3 column 4
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/psych.rb:205:in `parse'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/psych.rb:205:in `parse_stream'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/psych.rb:153:in `parse'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/psych.rb:129:in `load'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/psych.rb:299:in `block in load_file'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/psych.rb:299:in `open'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/psych.rb:299:in `load_file'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.29.0/lib/cocoapods/sources_manager.rb:261:in `version_information'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.29.0/lib/cocoapods/sources_manager.rb:222:in `repo_compatible?'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.29.0/lib/cocoapods/sources_manager.rb:281:in `master_repo_functional?'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.29.0/lib/cocoapods/command.rb:39:in `parse'
/Library/Ruby/Gems/2.0.0/gems/claide-0.4.0/lib/claide/command.rb:179:in `parse'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.29.0/lib/cocoapods/command.rb:38:in `parse'
/Library/Ruby/Gems/2.0.0/gems/claide-0.4.0/lib/claide/command.rb:211:in `run'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.29.0/lib/cocoapods/command.rb:51:in `run'
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.29.0/bin/pod:24:in `'
/usr/bin/pod:23:in `load'
/usr/bin/pod:23:in `'
―――――――――― TEMPLATE END ――――――――――
[!] Oh no, an error occurred.
Search for existing github issues similar to yours:
If none exists, create a ticket, with the template displayed above, on:
https://github.com/CocoaPods/CocoaPods/issues/new
Don't forget to anonymize any private data!
解决方案:
$ sudo rm -rf ~/.cocoapods/repos/master
$ pod setup