platform:ios,7.0
pod 'SDWebImage'
pod 'MBProgressHUD'
pod 'AFNetworking'
pod 'MFSideMenu'
#pod 'ZBarSDK', '~> 1.3.1'
最新版本-後面不能添加版本號;
指定 SDK 版本
CocoaPods 中,有幾種設置 SDK 版本的方法。如:
'>= 2.4.X' 會根據您本地的 CocoaPods 源列表,導入不低於 2.4.X 版本的 SDK。
'~> 2.4.X' 會根據您本地的 CocoaPods 源列表,介於 2.4.X~2.5.0 以前版本的 SDK。
咱們建議您鎖定版本,便於團隊開發。如,指定 2.4.X 版本。
$ sudo gem install cocoapods
1.During this process RubyGems might ask you if you want to overwrite the rake
executable. This warning is raised because the rake
gem will be updated as part of this process. Simply confirm by typing y
.
在此過程當中的RubyGems可能會問你,若是你要覆蓋耙
可執行文件。這個警告是由於引起了耙
寶石將被更新,這個過程的一部分。只需鍵入確認ÿ
。
第一次用sudo的時候會有一個警告:
WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.
To proceed, enter your password, or type Ctrl-C to abort.
警告:錯誤的使用sudo工具會致使數據丟失,或者缺失重要的系統文件。請複覈你的鍵入,當使用sudo。 鍵入 man sudo 獲得更多信息。
2.If you do
not want to grant RubyGems admin privileges for this process, you can tell RubyGems to install into your user directory by passing either the
--user-install
flag to
gem install
or by configuring the RubyGems environment. The latter is in our opinion the best solution. To do this, create or edit the
.profile
file in your home directory and add or amend it to include these lines:
若是你
不
但願授予RubyGems的管理員權限這個過程當中,你能夠告訴RubyGems的傳遞不管是安裝到你的用戶目錄
--user-install
標誌
gem install
或配置RubyGems的環境。後者是咱們認爲最好的解決方案。要作到這一點,建立或編輯
.profile
文件在你的home目錄下,並添加或修改它包含這些行:
博客地址:
http://www.easymorse.com/index.php/archives/672php
-------------------------------------------------------------------------------------------------------------------------
一.檢查是否安裝了必要得工具。
若是安裝了Xcode,那麼git就已經安裝了,能夠確認一下:
1.ruby -v:檢查ruby有沒有啊,親!
zhuxinmingdeMacBook-Pro:~ simon$
ruby -v
ruby 2.0.0p645 (2015-04-13 revision 50299) [universal.x86_64-darwin15]
2.git —version 確認安裝了git version 1.8.3.4
zhuxinmingdeMacBook-Pro:~ simon$
git —-version
git version 2.5.4 (Apple Git-61)
Unknown option: -version
usage: git [--version] [--help] [-C <path>] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
3.檢查是否 安裝Xcode的Command line工具,若是您的xcode未安裝Command Line Tools將會報錯
二.更新Ruby環境下的gem
RubyGems(簡稱 gems)是一個用於對 Rails 組件進行打包的 Ruby 打包系統。 它提供一個分發 Ruby 程序和庫的標準格式,還提供一個管理程序包安裝的工具。(能夠到這個網址http://www.
ruby-lang.org/查看ruby版本是否最新。)
1.gem update+空格+--system
XinMinghudeiMac:~ Simon$ gem update --system
(1)若是更新失敗:
Updating rubygems-update
Fetching: rubygems-update- 2.5.1.gem
(100%)—表示有最新的gems環境2.4.5版本。
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
表示沒有寫入權限:
若是出現沒有權限,多加一個sudo。
sudo gem update+空格+—system
(2)若是已是最新的版本:
則回覆爲Latest version currently installed. Aborting.
------
(3)若是須要更新且更新成功:
Updating rubygems-update
Fetching: rubygems-update-2.5.1.gem (100%)Fetching: rubygems-update-2.5.1.gem
Successfully installed rubygems-update-2.5.1
Parsing documentation for rubygems-update-2.5.1
Installing ri documentation for rubygems-update-2.5.1
Installing darkfish documentation for rubygems-update-2.5.1
Parsing documentation for rubygems-update-2.5.1
Installing RubyGems 2.5.1
RubyGems 2.5.1 installed
------------------------------------------------------------------------------
RubyGems installed the following executables(可執行文件):
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/gem
Ruby Interactive (ri) documentation was installed. ri is kind of like man
pages for ruby libraries. You may access it like this:
ri Classname
ri Classname.class_method
ri Classname#instance_method
If you do not wish to install this documentation in the future, use the
--no-document flag, or set it as the default in your ~/.gemrc file. See
'gem help env' for details.
RubyGems system software updated
zhuxinmingdeMacBook-Pro:~ simon$
--------------------------------------------------------------------------------
1.若是執行gem的時候返回出錯,
(1)返回出錯1:返回以下:
ERROR: Could not find a valid gem 'cocoapods' (>= 0), here is why:
緣由:牆攔截了。
(2)返回出錯2:返回以下:
ERROR: While executing gem ... (Gem::RemoteFetcher::UnknownHostError)
緣由:牆攔截了。
(3) 返回出錯3:返回以下:(不支持https)
-------------------------------
解決:咱們能夠經過替換rubygems鏡像爲淘寶的Ruby鏡像,在終端輸入以下命令將Ruby鏡像替換爲淘寶的;
$ gem sources --add https://ruby.taobao.org/ - 再添加;
//或者用淘寶的:
----------------------------------------------------
2.檢查:gem鏡像環境:
$ gem sources
zhuxinmingdeMacBook-Pro:MusicBa simon$ gem sources
*** CURRENT SOURCES ***
若是輸出是如下這樣,說明仍是原來的rubygems;
-----------------------------------------
三.安裝CocoaPods
安裝CocoaPods以前,先確保本地有Ruby環境,由於CocoaPods運行於Ruby之上,默認狀況下,Mac是自帶了Ruby環境的,能夠經過命令行ruby -v查看當前Ruby的版本。接下來咱們就能夠經過以下命令安裝CocoaPods了。
$ sudo gem install cocoapods
----------------------------------------------------
若是是第一次使用sudo:會出現警告;
WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.
警告:sudo命令的不當使用可能會致使數據丟失
或刪除重要的系統文件
不用管,不要緊的。
To proceed, enter your password, or type Ctrl-C to abort.
Fetching: i18n-0.6.9.gem (100%)
Successfully installed i18n-0.6.9
Fetching: multi_json-1.8.2.gem (100%)
Successfully installed multi_json-1.8.2
Fetching: activesupport-3.2.16.gem (100%)
Successfully installed activesupport-3.2.16
Fetching: nap-0.6.0.gem (100%)
Successfully installed nap-0.6.0
Fetching: json_pure-1.8.1.gem (100%)
Successfully installed json_pure-1.8.1
Fetching: fuzzy_match-2.0.4.gem (100%)
Successfully installed fuzzy_match-2.0.4
Fetching: cocoapods-core-0.29.0.gem (100%)
Successfully installed cocoapods-core-0.29.0
Fetching: claide-0.4.0.gem (100%)
Successfully installed claide-0.4.0
Fetching: cocoapods-downloader-0.3.0.gem (100%)
Successfully installed cocoapods-downloader-0.3.0
Fetching: rake-10.1.1.gem (100%)
rake's executable "rake" conflicts with /usr/bin/
ERROR: Error installing cocoapods:
"rake" from rake conflicts with /usr/bin/rake
若是出現rake's executable "rake" conflicts with /usr/bin/rake
Overwrite the executable? [yN] y
則y來重寫衝突。
(2)返回出錯二:
Setting up CocoaPods master repohtml
[!] /usr/bin/git clone 'https://github.com/CocoaPods/Specs.git' master --depth=1ios
Cloning into 'master'...git
error: RPC failed; result=52, HTTP code = 0github
fatal: The remote end hung up unexpectedly
檢查是否安裝成功cocoapods:
$ pod repo list
若是是如下則表示已安裝成功:
(3) 返回錯誤三:
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /usr/bin/pod
解決辦法
sudo gem install -n /usr/local/bin cocoapods
------------------
2.若是返回成功:
查看當前cocoapods的版本:gem which cocoapods
ZhuXinMingdeMac-mini:~ zhuxinming$ gem which cocoapods
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.39.0/lib/cocoapods.rb
-------------------------------
(四)更新cocoaPods
若是須要更新CocoaPods到最新版本輸入以下命令:
一、若是想爲每一個第三方庫生成文檔,那運行
brew install appledoc 這步是可選的。
安裝完成後提示:
錯誤:遇到 Executable pull--
在安裝了cocoapods,系統又更新到最新版本os x的時候,遇到錯誤
。
echodeiMac:~ echo$ pod setup
Setting up CocoaPods master repo
[!] Pod::Executable pull
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a’.json
解決辦法 可使用 pod repo remove master; pod setup
echodeiMac:~ echo$
pod repo remove master
Removing spec repo `master`
echodeiMac:~ echo$
pod setup
Setting up CocoaPods master repo
Setup completed (read-only access)
解決方法:vim
$ pod repo remove master
$ pod setup
若是還不行則從新安裝:
pod$ sudo rm -rf ~/.cocoapods/
$ pod setup
五:搜索第三方庫
若是你須要什麼庫,能夠用pod來搜索,好比搜索JSONKit這個庫:
pod search JSONKit
可能會出現:Setting up CocoaPods master repo
六.安裝第三方庫:初始化,進入app目錄,新建一個名爲Podfile的文件.
檢測完畢後咱們來到工程CocoaPodsTest的目錄下,新建一個名爲Podfile的文件(這裏經過命令行建立)
- $ vim Podfile
這個Podfile文件的做用是配置依賴庫信息,就是告訴CocoaPods去下載和管理哪些依賴庫,文件建立好之後,打開文件並加入以下內容。(vim打開文件後按i進入插入模式,編輯完成後按esc退出編輯模式,接着輸入:wq保存並退出文件)
cd+空格+app拖進來的目錄
appletekiiMac:~ apple$
cd /Users/apple/Desktop/DingXi //初始化,進入app目錄
appletekiiMac:DingXi apple$
touch Podfile //新建一個名爲Podfile的文件
appletekiiMac:DingXi apple$
open Podfile //打開文件————換電腦後,這個從新打開,寫加載的開源
在打開的文件輸入:
platform:ios,6.1
pod 'SDWebImage’, '~> 3.7.1'
pod 'ZBarSDK', '~> 1.3.1'
pod 'ZXing', '~> 2.3’ //不要加這個,配置有問題,這個配置太繁瑣了;
pod 'ZXingObjC', '~> 3.0.3'
pod 'UIActivityIndicator-for-SDWebImage', '~> 1.2'
pod 'SDWebImage-ProgressView', '~> 0.4.0'
pod'ASIHTTPRequest','~> 1.8.2'
pod'MBProgressHUD','~> 0.8
’
若是沒有輸入正確,或許有換行符。會報錯。
unterminated string meets end of file
執行命令:
pod install
看仔細過程: pod install –verbose
其中
Pods目錄是一個xcode項目,裏面包含全部在Podfile中聲明的第三方庫代碼;
App.
xcworkspace 爲xcode的工做空間文件,之後用這個文件來打開項目;
Podfile.lock 文件記錄全部已安裝的代碼庫的描述(不可更改),文件以下:
注意點:
- 使用CocoaPods生成的.xcworkspace 文件來打開工程,而不是之前的 .xcodeproj 文件。
- 每次更改了Podfile文件,cd+空格+app拖進來的目錄,你須要從新執行一次 Pod install命令。
- 運行時項目名稱選擇你本身的項目名稱而不是Pods
一.啓動程序致使的報錯:
diff: /../Podfile.lock: No such file or directory diff: /Manifest.lock: No such file or directory error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.
或者出現這種錯誤:
/Users/zhuxinming/Library/Developer/Xcode/DerivedData/NBEntertainment-clgpubjdvgopgzbhnrovxswhlixt/Build/Intermediates/NBEntertainment.build/Debug-iphonesimulator/NBEntertainment.build/Script-8487E21DF0D3490EBAC94484.sh: line 2: /Users/zhuxinming/Desktop/海曙文化協會/Pods/Pods-resources.sh: Permission denied
pod 沒有權限。(多是換了電腦致使)--
解決辦法:
進入到工程目錄pod install 從新安裝一下。
————————————————————————————————
——————————————————————————
zhuxinmingdeMacBook-Pro:ShiChunTang simon$ pod install
/Library/Ruby/Gems/2.0.0/gems/cocoapods-0.34.4/lib/cocoapods/user_interface/error_report.rb:13:in `report': incompatible character encodings: UTF-8 and ASCII-8BIT (Encoding::CompatibilityError)不兼容的字符編碼:utf - 8和ASCII-8BIT(編碼::CompatibilityError)
from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.34.4/lib/cocoapods/command.rb:63:in `report_error'
from /Library/Ruby/Gems/2.0.0/gems/claide-0.7.0/lib/claide/command.rb:300:in `handle_exception'
from /Library/Ruby/Gems/2.0.0/gems/claide-0.7.0/lib/claide/command.rb:274:in `rescue in run'
from /Library/Ruby/Gems/2.0.0/gems/claide-0.7.0/lib/claide/command.rb:264:in `run'
from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.34.4/lib/cocoapods/command.rb:50:in `run'
from /Library/Ruby/Gems/2.0.0/gems/cocoapods-0.34.4/bin/pod:33:in `<top (required)>'
from /usr/bin/pod:23:in `load'
from /usr/bin/pod:23:in `<main>'
------------------------------------------------------------------------
pod install
Ignoring xcodeproj-0.16.1 because its extensions are not built. Try: gem pristine xcodeproj-0.16.1
Ignoring xcodeproj-0.17.0 because its extensions are not built. Try: gem pristine xcodeproj-0.17.0
/Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- xcodeproj/prebuilt/universal.x86_64-darwin14-2.0.0/xcodeproj_ext (LoadError)
擴展沒有創建,嘗試 gem pristine xcodeproj-0.16.1
運行這個也是這個結果。
ZhuXinMingdeMac-mini:baohuai_iPhone 2.4 zhuxinming$ pod repo remove master
Ignoring xcodeproj-0.16.1 because its extensions are not built. Try: gem pristine xcodeproj-0.16.1
-----------
問題1:
[!] CocoaPods was not able to update the `master` repo. If this is an unexpected issue and persists you can inspect it running `pod repo update --verbose`
清除CocoaPods緩存後從新pod setup,解決問題.
sudo rm -fr ~/.cocoapods/repos/master
pod setup
簡單來講就是0.32以後的CocoaPods repo目錄訪問如今不須要root權限了,以前版本生成的目錄權限在新版本下會有權限問題,因此須要刪除從新生成一次。
--------------------
官方文檔翻譯:
The dependencies for your projects are specified in a single text file called a Podfile. CocoaPods will resolve dependencies between libraries, fetch the resulting source code, then link it together in an Xcode workspace to build your project.
指定項目的依賴關係在一個文本文件稱爲Podfile。CocoaPods將解決庫之間的依賴關係,獲取生成的源代碼,而後聯繫在一塊兒,一個Xcode工做區來構建您的項目。
CocoaPods is built with Ruby and it will be installable with the default Ruby available on OS X. You can use a Ruby Version manager, however we recommend that you use the standard Ruby available on OS X unless you know what you're doing.api
Using the default Ruby install will require you to use sudo
when installing gems. (This is only an issue for the duration of the gem installation, though.)xcode
CocoaPods構建Ruby和它將與默認安裝Ruby能夠在OS X經理可使用Ruby版本,可是咱們建議你使用標準的Ruby能夠在OS X上,除非你知道你在作什麼。
使用默認的Ruby安裝須要你安裝時使用sudo寶石。(這只是一個問題的時間gem安裝。)
If you encounter any problems during installation, please visit this guide.緩存
若是你在安裝過程當中遇到任何問題,請訪問本指南。
If you do
not want to grant RubyGems admin privileges for this process, you can tell RubyGems to install into your user directory by passing either the
--user-install
flag to
gem install
or by configuring the RubyGems environment. The latter is in our opinion the best solution. To do this, create or edit the
.profile
file in your home directory and add or amend it to include these lines:
if你不想RubyGems admin特權授予這個過程,你能夠告訴RubyGems安裝到您的用戶目錄經過——user-install國旗gem安裝或配置RubyGems的環境。後者是咱們認爲最好的解決辦法。爲此,建立或編輯。概要文件在您的主目錄,添加或修改包括這些線:
Updating CocoaPods
To update CocoaPods you simply install the gem again 從新安裝就行
$ [sudo] gem install cocoapods
Or for a pre-release version 或者一個預發佈版本
$ [sudo] gem install cocoapods --pre
If you originally installed the cocoapods gem using sudo, you should use that command again.
Later on, when you're actively using CocoaPods by installing pods, you will be notified when new versions become available with a CocoaPods X.X.X is now available, please update message.
Using a CocoaPods Fork
There is a guide for using a version of CocoaPods to try new features that are in discussion or in implementation stage.
若是您最初安裝了cocoapods gem使用sudo,您應該使用command again。
後來,當你積極使用CocoaPods經過安裝pods,時會通知你新版本可用CocoaPods X.X.如今X是可用的,請更新消息。
使用CocoaPods Fork
有一個指南使用的一個版本CocoaPods嘗試新功能討論或實現階段。
Using CocoaPods
Adding Pods to an Xcode project
Before you begin
- Check the Specs repository or cocoapods.org to make sure the libraries you would like to use are available.
- Install CocoaPods on your computer.