博客> cocoaPods 安装和使用
cocoaPods 安装和使用
2019-01-22 08:01 评论:0 阅读:1153 zhaolei
ios cocoapods

cocoaPods是啥?

简单的说就是个管理第三方开源库的玩意,比如MJRefresh之类的。想要啥,只要在podfile文件中加一行就行,然后pod install一下,第三方库就加到工程中了,很简单,现在来安装吧。

安装 安装前先检查下Ruby有没有安装  这样表示安装好了。

在终端输入以下命令:

$ sudo gem install -n /usr/local/bin cocoapods 如果没有反应,则输入: $ gem sources --remove https://rubygems.org/ 然后再输入: $ gem sources -a http://gems.ruby-china.org/ 然后再次在终端运行: $ sudo gem install -n /usr/local/bin cocoapods

等会就会安装好滴。

报错问题: //如果发生以下问题

$ sudo gem install cocoapods ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /usr/bin directory. $ pod --version /Library/Ruby/Site/2.3.0/rubygems.rb:271:in find_spec_for_exe': can't find gem cocoapods (>= 0.a) (Gem::GemNotFoundException) from /Library/Ruby/Site/2.3.0/rubygems.rb:299:inactivate_bin_path' from /usr/local/bin/pod:23:in `

' //解决方案: //我这里显示已经更新了 $ sudo gem update --system Latest version currently installed. Aborting. $ mkdir -p $HOME/Software/ruby $ export GEM_HOME=$HOME/Software/ruby $ gem install cocoapods 显示: Fetching: xcodeproj-1.5.6.gem (100%) Successfully installed xcodeproj-1.5.6 Fetching: cocoapods-1.4.0.gem (100%) Successfully installed cocoapods-1.4.0 Parsing documentation for xcodeproj-1.5.6 Installing ri documentation for xcodeproj-1.5.6 Parsing documentation for cocoapods-1.4.0 Installing ri documentation for cocoapods-1.4.0 Done installing documentation for xcodeproj, cocoapods after 7 seconds 2 gems installed

$ export PATH=$PATH:$HOME/Software/ruby/bin //这个时候查看下pod的版本,不报错了 $ pod --version 显示1.4.0

使用 就拿MJRefresh举例,先用终端搜索下 $ pod search AFNetworking   然后咱创建个Demo项目,在这个项目目录下创建一个叫“Podfile”的文件,这里用终端来创建,我们先到这个项目的目录下,输入 $ vim Podfile 然后在vim中输入i进入编辑模式 source 'https://github.com/CocoaPods/Specs.git' target :RuntimeTest do platform:ios,'9.0' pod 'MJRefresh', '~> 3.1.15.3' end 按esc退出编辑模式,再输入:wq 这样就保存退出了 最后运行下面命令 $ pod install Analyzing dependencies Downloading dependencies Installing MJRefresh (3.1.15.3) Generating Pods project Integrating client project [!] Please close any current Xcode sessions and use RuntimeTest.xcworkspace for this project from now on. Sending stats Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed. 运行成功了然后打开RuntimeTest.xcworkspace这个文件就完事了

收藏
0
sina weixin mail 回到顶部