【iOS工具】Cocoapods的安装使用
----先检查是否安装
1.安装好Ruby环境:https://ruby-china.org/wiki/install_ruby_guide
2.安装步骤可以参考:http://code4app.com/article/cocoapods-install-usage
下面我再写一下,
//移除rubygem $ gem sources --remove https://rubygems.org/ //等有反应之后再敲入以下命令 $ gem sources -a http://ruby.taobao.org/ //验证,成功会输出http://ruby.taobao.org/ $ gem sources -l //开始安装 ,需要稍等片刻 $ sudo gem install cocoapods
备注:淘宝源 改到 http://gems.ruby-china.org/
3.使用CocoaPods
eg1.参考第三方高德地图自动配置SDK http://lbs.amap.com/api/ios-sdk/guide/deploy/
eg2.afnetworking 下面写一下
$ pod search AFNetworking $ vim Podfile //在podfile文件中输入:(库提供的) platform :ios, '7.0' pod "AFNetworking", "~> 2.0" //保存退出 $:wq //Podfile文件应该和你的工程文件.xcodeproj在同一个目录下。 $ pod install //正常的话输出: Analyzing dependencies Downloading dependencies Installing AFNetworking (2.0.2) Generating Pods project Integrating client project [!] From now on use `CocoaPodsDemo.xcworkspace`. //最后一句话,意思是:以后打开项目就用 CocoaPodsDemo.xcworkspace 打开,而不是之前的.xcodeproj文件
总结:
- 先在项目中创建Podfile,Podfile的内容是你想导入的类库。一般类库的原作者会告诉你导入该类库应该如何写Podfile;
- 运行命令:
`$ pod install
.
4.如何正确编译运行一个包含CocoPods类库的项目,参考2.的链接
5.从工程中删除Cocoapods http://blog.csdn.net/freedom2028/article/details/10244819
6.CocoaPods 编译、使用中的一些问题和警告
---pod install 后 控制台输出
[!] The `Paopao [Release]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods/Pods.release.xcconfig'. This can lead to problems with the CocoaPods installation - Use the `$(inherited)` flag, or - Remove the build settings from the target.
答:可以参考 http://www.cnblogs.com/ihojin/p/xcode6-cocoapods-error.html
- 在 Finder 中找到 项目名.xcodeproj,右键选择显示包内容
- 用文本编辑器打开 project.pbxproj,搜索
OTHER_LDFLAGS
- 若项目未运行
pod install
则会看到2处类似格式的语句
OTHER_LDFLAGS = "";
将其删除后运行
pod install
即可若已运行
pod install
则删除2处如下格式的语句
<key>OTHER_LDFLAGS</key> <string></string>
---其他问题后续加上
//source https://rubygems.org/ not present in cache 遇到这个问题时,按下面的再走一遍......
➜ ~ git:(master) ✗ sudo gem install cocoapods ERROR: Could not find a valid gem 'cocoapods' (>= 0), here is why: Unable to download data from http://ruby.taobao.org/ - bad response Not Found 404 (http://ruby.taobao.org/latest_specs.4.8.gz) ➜ ~ git:(master) ✗ gem sources -l *** CURRENT SOURCES *** http://ruby.taobao.org/ ➜ ~ git:(master) ✗ gem sources --remove https://rubygems.org/ source https://rubygems.org/ not present in cache ➜ ~ git:(master) ✗ gem sources -a https://ruby.taobao.org/ https://ruby.taobao.org/ added to sources ➜ ~ git:(master) ✗ gem sources -l *** CURRENT SOURCES *** http://ruby.taobao.org/ https://ruby.taobao.org/ ➜ ~ git:(master) ✗ sudo gem install cocoapods
问题:在swift 中出现linker command failed with exit code 1 (use -v to see invocation)
解决,重新装一下cocoapods 或者sudo gem install cocoapods --pre 再 pod install
platform :ios, '8.0' #swift库 需要加这个 use_frameworks! target 'LearnSwift' do # tools pod 'MJRefresh' end
安装cocopods时, 出现Setting up CocoaPods master repo,半天没有任何反应。