CocoaPods安裝與使用

CocoaPods是iOS項(xiàng)目的依賴(lài)管理工具吼渡。使用它不需要我們自己去下載第三方開(kāi)源庫(kù)的代碼并且放進(jìn)自己的項(xiàng)目中低葫,它會(huì)將第三方開(kāi)源庫(kù)的代碼下載下來(lái)并且設(shè)置好相應(yīng)的系統(tǒng)依賴(lài)和編譯參數(shù)。
最新ruby源查詢(xún):Ruby China

安裝
  • 設(shè)置ruby源: ruby的軟件源rubygems.org因?yàn)槭褂脕嗰R遜的云服務(wù)伟恶,在國(guó)內(nèi)不能使用,所以要更換ruby源。

打開(kāi)終端:

terminal.png
  • 查看當(dāng)前ruby源:
gem sources

結(jié)果:


gemsources.png

當(dāng)前我的mac上的ruby源為:

https://gems.ruby-china.org/

我這是更換后的宦焦,如果你的是:

https://rubygems.org/

需要更換為前者。

  • 移除當(dāng)前ruby源:
gem sources --remove https://rubygems.org/
gemsourcesremove.png
  • 添加新的ruby源:
gem sources -a https://gems.ruby-china.org/
gemsourcesa.png

再次查看當(dāng)前ruby源顿涣,已經(jīng)更換:

curren.png
  • 查看當(dāng)前gem版本:
gem -v
version.png
  • 如果gem版本過(guò)低波闹,可以嘗試以下方式升級(jí):

使用命令:

gem update --system

報(bào)錯(cuò):

macdeMacBook-Pro:~ mac$ gem update --system
Updating rubygems-update
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

這個(gè)暫時(shí)沒(méi)理會(huì),換個(gè)命令:

sudo gem update --system

仍然報(bào)錯(cuò):

macdeMacBook-Pro:~ mac$ sudo gem update --system
Password:
Updating rubygems-update
ERROR:  While executing gem ... (OpenSSL::SSL::SSLError)
    hostname "upyun.gems.ruby-china.org" does not match the server certificate

Password:處我輸入的為開(kāi)機(jī)密碼涛碑,不清楚到底是不是精堕。

接著我又執(zhí)行一次剛才的命令:sudo gem update --system

然后,升級(jí)成功了蒲障!

Updating rubygems-update
Fetching: rubygems-update-2.6.7.gem (100%)
Successfully installed rubygems-update-2.6.7
Parsing documentation for rubygems-update-2.6.7
Installing ri documentation for rubygems-update-2.6.7
Installing darkfish documentation for rubygems-update-2.6.7
Installing RubyGems 2.6.7
RubyGems 2.6.7 installed
Parsing documentation for rubygems-2.6.7
Installing ri documentation for rubygems-2.6.7

=== 2.6.7 / 2016-09-26

Bug fixes:

* Install native extensions in the correct location when using the
  `--user-install` flag. Pull request #1683 by Noah Kantrowitz.
* When calling `Gem.sources`, load sources from `configuration`
  if present, else use the default sources. Pull request #1699
  by Luis Sagastume.
* Fail gracefully when attempting to redirect without a Location.
  Pull request #1711 by Samuel Giddins.
* Update vendored Molinillo to 0.5.1. Pull request #1714 by
  Samuel Giddins.

=== 2.6.6 / 2016-06-22

Bug fixes:

* Sort installed versions to make sure we install the latest version when
  running `gem update --system`. As a one-time fix, run
  `gem update --system=2.6.6`. Pull request #1601 by David Radcliffe.

=== 2.6.5 / 2016-06-21

Minor enhancements:

* Support for unified Integer in Ruby 2.4. Pull request #1618
  by SHIBATA Hiroshi.
* Update vendored Molinillo to 0.5.0 for performance improvements.
  Pull request #1638 by Samuel Giddins.

Bug fixes:

* Raise an explicit error if Signer#sign is called with no certs. Pull
  request #1605 by Daniel Berger.
* Update `update_bundled_ca_certificates` utility script for directory
  nesting. Pull request #1583 by James Wen.
* Fix broken symlink support in tar writer (+ fix broken test). Pull
  request #1578 by Cezary Baginski.
* Remove extension directory before (re-)installing. Pull request #1576
  by Jeremy Hinegardner.
* Regenerate test CA certificates with appropriate extensions. Pull
  request #1611 by rhenium.
* Rubygems does not terminate on failed file lock when not superuser. Pull
  request #1582 by Ellen Marie Dash.
* Fix tar headers with a 101 character name. Pull request #1612 by Pawe?
  Tomulik.
* Add Gem.platform_defaults to allow implementations to override defaults.
  Pull request #1644 by Charles Oliver Nutter.
* Run Bundler tests on TravisCI. Pull request #1650 by Samuel Giddins.

=== 2.6.4 / 2016-04-26

Minor enhancements:

* Use Gem::Util::NULL_DEVICE instead of hard coded strings. Pull request #1588
  by Chris Charabaruk.
* Use File.symlink on MS Windows if supported. Pull request #1418
  by Nobuyoshi Nakada.

Bug fixes:

* Redact uri password from error output when gem fetch fails. Pull request
  #1565 by Brian Fletcher.
* Suppress warnings. Pull request #1594 by Nobuyoshi Nakada.
* Escape user-supplied content served on web pages by `gem server` to avoid
  potential XSS vulnerabilities. Samuel Giddins.

=== 2.6.3 / 2016-04-05

Minor enhancements:

* Lazily calculate Gem::LoadError exception messages. Pull request #1550
  by Aaron Patterson.
* New fastly cert. Pull request #1548 by David Radcliffe.
* Organize and cleanup SSL certs. Pull request #1555 by James Wen.
* [RubyGems] Make deprecation message for paths= more helpful. Pull
  request #1562 by Samuel Giddins.
* Show default gems when using "gem list". Pull request #1570 by Luis
  Sagastume.

Bug fixes:

* Stub ordering should be consistent regardless of how cache is populated.
  Pull request #1552 by Aaron Patterson.
* Handle cases when the @@stubs variable contains non-stubs. Pull request
  #1558 by Per Lundberg.
* Fix test on Windows for inconsistent temp path. Pull request #1554 by
  Hiroshi Shirosaki.
* Fix `Gem.find_spec_for_exe` picks oldest gem. Pull request #1566 by
  Shinichi Maeshima.
* [Owner] Fallback to email and userid when owner email is missing. Pull
  request #1569 by Samuel Giddins.
* [Installer] Handle nil existing executable. Pull request #1561 by Samuel
  Giddins.
* Allow two digit version numbers in the tests. Pull request #1575 by unak.

=== 2.6.2 / 2016-03-12

Bug fixes:

* Fix wrong version of gem activation for bin stub. Pull request #1527 by
  Aaron Patterson.
* Speed up gem activation failures. Pull request #1539 by Aaron Patterson.
* Fix platform sorting in the resolver. Pull request #1542 by Samuel E.
  Giddins.
* Ensure we unlock the monitor even if try_activate throws. Pull request
  #1538 by Charles Oliver Nutter.


=== 2.6.1 / 2016-02-28

Bug fixes:

* Ensure `default_path` and `home` are set for paths. Pull request #1513
  by Aaron Patterson.
* Restore but deprecate support for Array values on `Gem.paths=`. Pull
  request #1514 by Aaron Patterson.
* Fix invalid gem file preventing gem install from working. Pull request
  #1499 by Luis Sagastume.

=== 2.6.0 / 2016-02-26

Minor enhancements:

* RubyGems now defaults the `gem push` to the gem's "allowed_push_host"
  metadata setting.  Pull request #1486 by Josh Lane.
* Update bundled Molinillo to 0.4.3. Pull request #1493 by Samuel E. Giddins.
* Add version option to gem open command. Pull request #1483 by Hrvoje
  ?imi?.
* Feature/add silent flag. Pull request #1455 by Luis Sagastume.
* Allow specifying gem requirements via env variables. Pull request #1472
  by Samuel E. Giddins.

Bug fixes:

* RubyGems now stores `gem push` credentials under the host you signed-in for.
  Pull request #1485 by Josh Lane.
* Move `coding` location to first line. Pull request #1471 by SHIBATA
  Hiroshi.
* [PathSupport] Handle a regexp path separator. Pull request #1469 by
  Samuel E. Giddins.
* Clean up the PathSupport object. Pull request #1094 by Aaron Patterson.
* Join with File::PATH_SEPARATOR in Gem.use_paths. Pull request #1476 by
  Samuel E. Giddins.
* Handle when the gem home and gem path arent set in the config file. Pull
  request #1478 by Samuel E. Giddins.
* Terminate TimeoutHandler. Pull request #1479 by Nobuyoshi Nakada.
* Remove redundant cache. Pull request #1482 by Eileen M. Uchitelle.
* Freeze `Gem::Version@segments` instance variable. Pull request #1487 by
  Ben Dean.
* Gem cleanup is trying to uninstall gems outside GEM_HOME and reporting
  an error after it tries. Pull request #1353 by Luis Sagastume.
* Avoid duplicated sources. Pull request #1489 by Luis Sagastume.
* Better description for quiet flag. Pull request #1491 by Luis Sagastume.
* Raise error if find_by_name returns with nil. Pull request #1494 by
  Zoltán Hegedüs.
* Find_files only from loaded_gems when using gemdeps. Pull request #1277
  by Michal Papis.


------------------------------------------------------------------------------

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

終端過(guò)程:

macdeMacBook-Pro:~ mac$ gem sources
*** CURRENT SOURCES ***

https://rubygems.org/
macdeMacBook-Pro:~ mac$ gem sources --remove https://rubygems.org/
https://rubygems.org/ removed from sources
macdeMacBook-Pro:~ mac$ gem sources -a https://gems.ruby-china.org/
https://gems.ruby-china.org/ added to sources
macdeMacBook-Pro:~ mac$ gem sources
*** CURRENT SOURCES ***

https://gems.ruby-china.org/
macdeMacBook-Pro:~ mac$ gem -v
2.0.14.1
macdeMacBook-Pro:~ mac$ ruby -v
ruby 2.0.0p648 (2015-12-16 revision 53162) [universal.x86_64-darwin15]
macdeMacBook-Pro:~ mac$ gem update --system
Updating rubygems-update
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
macdeMacBook-Pro:~ mac$ sudo gem update --system
Password:
Updating rubygems-update
ERROR:  While executing gem ... (OpenSSL::SSL::SSLError)
    hostname "upyun.gems.ruby-china.org" does not match the server certificate
macdeMacBook-Pro:~ mac$ sudo gem update --system
Updating rubygems-update
Fetching: rubygems-update-2.6.7.gem (100%)
Successfully installed rubygems-update-2.6.7
Parsing documentation for rubygems-update-2.6.7
Installing ri documentation for rubygems-update-2.6.7
Installing darkfish documentation for rubygems-update-2.6.7
Installing RubyGems 2.6.7
RubyGems 2.6.7 installed
Parsing documentation for rubygems-2.6.7
Installing ri documentation for rubygems-2.6.7

=== 2.6.7 / 2016-09-26

Bug fixes:

* Install native extensions in the correct location when using the
  `--user-install` flag. Pull request #1683 by Noah Kantrowitz.
* When calling `Gem.sources`, load sources from `configuration`
  if present, else use the default sources. Pull request #1699
  by Luis Sagastume.
* Fail gracefully when attempting to redirect without a Location.
  Pull request #1711 by Samuel Giddins.
* Update vendored Molinillo to 0.5.1. Pull request #1714 by
  Samuel Giddins.

=== 2.6.6 / 2016-06-22

Bug fixes:

* Sort installed versions to make sure we install the latest version when
  running `gem update --system`. As a one-time fix, run
  `gem update --system=2.6.6`. Pull request #1601 by David Radcliffe.

=== 2.6.5 / 2016-06-21

Minor enhancements:

* Support for unified Integer in Ruby 2.4. Pull request #1618
  by SHIBATA Hiroshi.
* Update vendored Molinillo to 0.5.0 for performance improvements.
  Pull request #1638 by Samuel Giddins.

Bug fixes:

* Raise an explicit error if Signer#sign is called with no certs. Pull
  request #1605 by Daniel Berger.
* Update `update_bundled_ca_certificates` utility script for directory
  nesting. Pull request #1583 by James Wen.
* Fix broken symlink support in tar writer (+ fix broken test). Pull
  request #1578 by Cezary Baginski.
* Remove extension directory before (re-)installing. Pull request #1576
  by Jeremy Hinegardner.
* Regenerate test CA certificates with appropriate extensions. Pull
  request #1611 by rhenium.
* Rubygems does not terminate on failed file lock when not superuser. Pull
  request #1582 by Ellen Marie Dash.
* Fix tar headers with a 101 character name. Pull request #1612 by Pawe?
  Tomulik.
* Add Gem.platform_defaults to allow implementations to override defaults.
  Pull request #1644 by Charles Oliver Nutter.
* Run Bundler tests on TravisCI. Pull request #1650 by Samuel Giddins.

=== 2.6.4 / 2016-04-26

Minor enhancements:

* Use Gem::Util::NULL_DEVICE instead of hard coded strings. Pull request #1588
  by Chris Charabaruk.
* Use File.symlink on MS Windows if supported. Pull request #1418
  by Nobuyoshi Nakada.

Bug fixes:

* Redact uri password from error output when gem fetch fails. Pull request
  #1565 by Brian Fletcher.
* Suppress warnings. Pull request #1594 by Nobuyoshi Nakada.
* Escape user-supplied content served on web pages by `gem server` to avoid
  potential XSS vulnerabilities. Samuel Giddins.

=== 2.6.3 / 2016-04-05

Minor enhancements:

* Lazily calculate Gem::LoadError exception messages. Pull request #1550
  by Aaron Patterson.
* New fastly cert. Pull request #1548 by David Radcliffe.
* Organize and cleanup SSL certs. Pull request #1555 by James Wen.
* [RubyGems] Make deprecation message for paths= more helpful. Pull
  request #1562 by Samuel Giddins.
* Show default gems when using "gem list". Pull request #1570 by Luis
  Sagastume.

Bug fixes:

* Stub ordering should be consistent regardless of how cache is populated.
  Pull request #1552 by Aaron Patterson.
* Handle cases when the @@stubs variable contains non-stubs. Pull request
  #1558 by Per Lundberg.
* Fix test on Windows for inconsistent temp path. Pull request #1554 by
  Hiroshi Shirosaki.
* Fix `Gem.find_spec_for_exe` picks oldest gem. Pull request #1566 by
  Shinichi Maeshima.
* [Owner] Fallback to email and userid when owner email is missing. Pull
  request #1569 by Samuel Giddins.
* [Installer] Handle nil existing executable. Pull request #1561 by Samuel
  Giddins.
* Allow two digit version numbers in the tests. Pull request #1575 by unak.

=== 2.6.2 / 2016-03-12

Bug fixes:

* Fix wrong version of gem activation for bin stub. Pull request #1527 by
  Aaron Patterson.
* Speed up gem activation failures. Pull request #1539 by Aaron Patterson.
* Fix platform sorting in the resolver. Pull request #1542 by Samuel E.
  Giddins.
* Ensure we unlock the monitor even if try_activate throws. Pull request
  #1538 by Charles Oliver Nutter.


=== 2.6.1 / 2016-02-28

Bug fixes:

* Ensure `default_path` and `home` are set for paths. Pull request #1513
  by Aaron Patterson.
* Restore but deprecate support for Array values on `Gem.paths=`. Pull
  request #1514 by Aaron Patterson.
* Fix invalid gem file preventing gem install from working. Pull request
  #1499 by Luis Sagastume.

=== 2.6.0 / 2016-02-26

Minor enhancements:

* RubyGems now defaults the `gem push` to the gem's "allowed_push_host"
  metadata setting.  Pull request #1486 by Josh Lane.
* Update bundled Molinillo to 0.4.3. Pull request #1493 by Samuel E. Giddins.
* Add version option to gem open command. Pull request #1483 by Hrvoje
  ?imi?.
* Feature/add silent flag. Pull request #1455 by Luis Sagastume.
* Allow specifying gem requirements via env variables. Pull request #1472
  by Samuel E. Giddins.

Bug fixes:

* RubyGems now stores `gem push` credentials under the host you signed-in for.
  Pull request #1485 by Josh Lane.
* Move `coding` location to first line. Pull request #1471 by SHIBATA
  Hiroshi.
* [PathSupport] Handle a regexp path separator. Pull request #1469 by
  Samuel E. Giddins.
* Clean up the PathSupport object. Pull request #1094 by Aaron Patterson.
* Join with File::PATH_SEPARATOR in Gem.use_paths. Pull request #1476 by
  Samuel E. Giddins.
* Handle when the gem home and gem path arent set in the config file. Pull
  request #1478 by Samuel E. Giddins.
* Terminate TimeoutHandler. Pull request #1479 by Nobuyoshi Nakada.
* Remove redundant cache. Pull request #1482 by Eileen M. Uchitelle.
* Freeze `Gem::Version@segments` instance variable. Pull request #1487 by
  Ben Dean.
* Gem cleanup is trying to uninstall gems outside GEM_HOME and reporting
  an error after it tries. Pull request #1353 by Luis Sagastume.
* Avoid duplicated sources. Pull request #1489 by Luis Sagastume.
* Better description for quiet flag. Pull request #1491 by Luis Sagastume.
* Raise error if find_by_name returns with nil. Pull request #1494 by
  Zoltán Hegedüs.
* Find_files only from loaded_gems when using gemdeps. Pull request #1277
  by Michal Papis.


------------------------------------------------------------------------------

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
  • 下載命令:
sudo gem install cocoapods

報(bào)錯(cuò):

macdeMacBook-Pro:~ mac$ sudo gem install cocoapods
Password:
Fetching: nanaimo-0.2.3.gem (100%)
Successfully installed nanaimo-0.2.3
Fetching: colored2-3.1.2.gem (100%)
Successfully installed colored2-3.1.2
Fetching: claide-1.0.1.gem (100%)
Successfully installed claide-1.0.1
Fetching: CFPropertyList-2.3.5.gem (100%)
Successfully installed CFPropertyList-2.3.5
Fetching: xcodeproj-1.4.4.gem (100%)
ERROR:  While executing gem ... (Errno::EPERM)
    Operation not permitted - /usr/bin/xcodeproj

找到一種解決方法是:
如果mac系統(tǒng)為OS X EI Capitan可以使用如下命令代替前面的命令執(zhí)行下載:

2017年09月29日更新: 電腦系統(tǒng)為High Sierra直接使用以下命令

sudo gem install -n /usr/local/bin cocoapods

這里會(huì)等待些許時(shí)間執(zhí)行下載:

macdeMacBook-Pro:~ mac$ sudo gem install -n /usr/local/bin cocoapods
Successfully installed xcodeproj-1.4.4
Fetching: ruby-macho-1.1.0.gem (100%)
Successfully installed ruby-macho-1.1.0
Fetching: nap-1.1.0.gem (100%)
Successfully installed nap-1.1.0
Fetching: molinillo-0.5.7.gem (100%)
Successfully installed molinillo-0.5.7
Fetching: gh_inspector-1.0.3.gem (100%)
Successfully installed gh_inspector-1.0.3
Fetching: fourflusher-2.0.1.gem (100%)
Successfully installed fourflusher-2.0.1
Fetching: escape-0.0.4.gem (100%)
Successfully installed escape-0.0.4
Fetching: cocoapods-try-1.1.0.gem (100%)
Successfully installed cocoapods-try-1.1.0
Fetching: netrc-0.7.8.gem (100%)
Successfully installed netrc-0.7.8
Fetching: cocoapods-trunk-1.2.0.gem (100%)
Successfully installed cocoapods-trunk-1.2.0
Fetching: cocoapods-stats-1.0.0.gem (100%)
Successfully installed cocoapods-stats-1.0.0
Fetching: cocoapods-search-1.0.0.gem (100%)
Successfully installed cocoapods-search-1.0.0
Fetching: cocoapods-plugins-1.0.0.gem (100%)
Successfully installed cocoapods-plugins-1.0.0
Fetching: cocoapods-downloader-1.1.3.gem (100%)
Successfully installed cocoapods-downloader-1.1.3
Fetching: cocoapods-deintegrate-1.0.1.gem (100%)
Successfully installed cocoapods-deintegrate-1.0.1
Fetching: fuzzy_match-2.0.4.gem (100%)
Successfully installed fuzzy_match-2.0.4
Fetching: thread_safe-0.3.6.gem (100%)
Successfully installed thread_safe-0.3.6
Fetching: tzinfo-1.2.3.gem (100%)
Successfully installed tzinfo-1.2.3
Fetching: minitest-5.10.2.gem (100%)
Successfully installed minitest-5.10.2
Fetching: i18n-0.8.4.gem (100%)
Successfully installed i18n-0.8.4
Fetching: activesupport-4.2.8.gem (100%)
Successfully installed activesupport-4.2.8
Fetching: cocoapods-core-1.2.1.gem (100%)
Successfully installed cocoapods-core-1.2.1
Fetching: cocoapods-1.2.1.gem (100%)
Successfully installed cocoapods-1.2.1
Parsing documentation for xcodeproj-1.4.4
Installing ri documentation for xcodeproj-1.4.4
Parsing documentation for ruby-macho-1.1.0
Installing ri documentation for ruby-macho-1.1.0
Parsing documentation for nap-1.1.0
Installing ri documentation for nap-1.1.0
Parsing documentation for molinillo-0.5.7
Installing ri documentation for molinillo-0.5.7
Parsing documentation for gh_inspector-1.0.3
Installing ri documentation for gh_inspector-1.0.3
Parsing documentation for fourflusher-2.0.1
Installing ri documentation for fourflusher-2.0.1
Parsing documentation for escape-0.0.4
Installing ri documentation for escape-0.0.4
Parsing documentation for cocoapods-try-1.1.0
Installing ri documentation for cocoapods-try-1.1.0
Parsing documentation for netrc-0.7.8
Installing ri documentation for netrc-0.7.8
Parsing documentation for cocoapods-trunk-1.2.0
Installing ri documentation for cocoapods-trunk-1.2.0
Parsing documentation for cocoapods-stats-1.0.0
Installing ri documentation for cocoapods-stats-1.0.0
Parsing documentation for cocoapods-search-1.0.0
Installing ri documentation for cocoapods-search-1.0.0
Parsing documentation for cocoapods-plugins-1.0.0
Installing ri documentation for cocoapods-plugins-1.0.0
Parsing documentation for cocoapods-downloader-1.1.3
Installing ri documentation for cocoapods-downloader-1.1.3
Parsing documentation for cocoapods-deintegrate-1.0.1
Installing ri documentation for cocoapods-deintegrate-1.0.1
Parsing documentation for fuzzy_match-2.0.4
Installing ri documentation for fuzzy_match-2.0.4
Parsing documentation for thread_safe-0.3.6
Installing ri documentation for thread_safe-0.3.6
Parsing documentation for tzinfo-1.2.3
Installing ri documentation for tzinfo-1.2.3
Parsing documentation for minitest-5.10.2
Installing ri documentation for minitest-5.10.2
Parsing documentation for i18n-0.8.4
Installing ri documentation for i18n-0.8.4
Parsing documentation for activesupport-4.2.8
unable to convert "\x84" from ASCII-8BIT to UTF-8 for lib/active_support/values/unicode_tables.dat, skipping
Installing ri documentation for activesupport-4.2.8
Parsing documentation for cocoapods-core-1.2.1
Installing ri documentation for cocoapods-core-1.2.1
Parsing documentation for cocoapods-1.2.1
Installing ri documentation for cocoapods-1.2.1
23 gems installed
  • 安裝:
pod setup

這里會(huì)在Setting up CocoaPods master repo這個(gè)狀態(tài)等待一段時(shí)間:

setup.png

安裝報(bào)錯(cuò):

error.png

這可能與網(wǎng)絡(luò)狀態(tài)有關(guān)系歹篓,重試了3次后安裝成功瘫证。

completed.png

使用

為了更好的說(shuō)明使用方式: 新建一個(gè)工程,名稱(chēng)為CocoaPodsTest庄撮,目錄結(jié)構(gòu):

content.png
  • 在工程根目錄下新建一個(gè)Podfile文件背捌,名字必須是Podfile。

    • 可以創(chuàng)建文件再放在工程根目錄下

    • 終端進(jìn)入工程根目錄洞斯,執(zhí)行touch Podfile命令創(chuàng)建:

touchpodfile.png
podfile.png
  • 打開(kāi)Podfile文件(命令: open -e Podfile): 第一次打開(kāi)此文件是個(gè)空白頁(yè)面毡庆,其內(nèi)容格式應(yīng)該配置為如下樣式:
platform :ios, '7.0'

target 'CocoaPodsTest' do

pod 'AFNetworking', '~> 2.0'
pod 'Masonry'
pod 'SDWebImage'
pod 'MJRefresh'

end

其中platform為配置平臺(tái),ios必須是小寫(xiě)且與之前的":"不能有空格烙如,后面的'7.0'為最低iOS SDK版本號(hào)么抗,有些第三方庫(kù)要求最低版本。

其中AFNetworking后面的2.0為當(dāng)前要引入的AFNetworking版本亚铁,如果不寫(xiě)翔曲,默認(rèn)為該第三方開(kāi)源庫(kù)的最新版本。

  • 配置好Podfile文件后保存漾月,在工程根目錄下終端執(zhí)行命令: pod install
install.png

綠色文字团赏,提醒我們以后打開(kāi)項(xiàng)目的時(shí)候應(yīng)該打開(kāi)生成的CocoaPodsTest.xcworkspace。

content.png
目錄.png

如果終端中報(bào)黃色字體:

signerror.png
[!] Smart quotes were detected and ignored in your Podfile. To avoid issues in the future, you should not use TextEdit for editing it. If you are not using TextEdit, you should turn off smart quotes in your editor of choice.

可能是你輸入的單引號(hào)不正確甸昏,檢查是不是輸入了中文的單引號(hào)顽分。


補(bǔ)充:

使用第三方庫(kù),使用#import引入第三方庫(kù)頭文件時(shí)施蜜,發(fā)現(xiàn)不提醒卒蘸,command + B編譯多次仍不提醒。

解決方法:
工程 -> TARGETS -> Build Settings -> Search Paths -> User Header Search Paths:

雙擊User Header Search Paths后的空白處翻默,點(diǎn)擊"+"號(hào)缸沃,輸入"$(PODS_ROOT)",修改搜索方式為recursive(遞歸方式查找)修械。

header.png

這樣在引入頭文件時(shí)就會(huì)自動(dòng)聯(lián)想出第三方庫(kù)的頭文件了趾牧。

刪除之前引入的某個(gè)第三方庫(kù)

在工程中找到Podfile文件,注銷(xiāo)掉想要?jiǎng)h除的某個(gè)開(kāi)源庫(kù)

podfilexcode.png

肯污,也可以直接打開(kāi)Podfile文件翘单,直接刪除某個(gè)開(kāi)源庫(kù),

podfile.png

再在終端中執(zhí)行一次pod install命令蹦渣,成功后即可刪除開(kāi)源庫(kù)哄芜。

delete.png

PS: mac系統(tǒng)升級(jí)為High Sierra后發(fā)現(xiàn)CocoaPods不能用了,執(zhí)行pod install命令時(shí)柬唯,報(bào)錯(cuò): -bash: /usr/local/bin/pod: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby: bad ...

然后我直接照著本教程重新更新ruby版本认臊、重新安裝了cocoaPods。


工程


2020年12月09日更新


image.png

依次執(zhí)行以下命令:

gem sources
gem sources --remove https://rubygems.org/
gem sources -a https://gems.ruby-china.com
sudo gem install -n /usr/local/bin cocoapods
pod setup
參考:

CocoaPods的安裝使用和常見(jiàn)問(wèn)題

更新CocoaPods碰到的問(wèn)題及知識(shí)點(diǎn)

多個(gè)TARGETS等請(qǐng)看CocoaPods官方說(shuō)明

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末锄奢,一起剝皮案震驚了整個(gè)濱河市失晴,隨后出現(xiàn)的幾起案子冤议,更是在濱河造成了極大的恐慌,老刑警劉巖师坎,帶你破解...
    沈念sama閱讀 212,542評(píng)論 6 493
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件恕酸,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡胯陋,警方通過(guò)查閱死者的電腦和手機(jī)蕊温,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,596評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門(mén),熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)遏乔,“玉大人义矛,你說(shuō)我怎么就攤上這事∶巳” “怎么了凉翻?”我有些...
    開(kāi)封第一講書(shū)人閱讀 158,021評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)捻激。 經(jīng)常有香客問(wèn)我制轰,道長(zhǎng),這世上最難降的妖魔是什么胞谭? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 56,682評(píng)論 1 284
  • 正文 為了忘掉前任垃杖,我火速辦了婚禮,結(jié)果婚禮上丈屹,老公的妹妹穿的比我還像新娘调俘。我一直安慰自己,他們只是感情好旺垒,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,792評(píng)論 6 386
  • 文/花漫 我一把揭開(kāi)白布彩库。 她就那樣靜靜地躺著,像睡著了一般先蒋。 火紅的嫁衣襯著肌膚如雪骇钦。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書(shū)人閱讀 49,985評(píng)論 1 291
  • 那天鞭达,我揣著相機(jī)與錄音司忱,去河邊找鬼皇忿。 笑死畴蹭,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的鳍烁。 我是一名探鬼主播叨襟,決...
    沈念sama閱讀 39,107評(píng)論 3 410
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼幔荒!你這毒婦竟也來(lái)了糊闽?” 一聲冷哼從身側(cè)響起梳玫,我...
    開(kāi)封第一講書(shū)人閱讀 37,845評(píng)論 0 268
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎右犹,沒(méi)想到半個(gè)月后提澎,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,299評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡念链,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,612評(píng)論 2 327
  • 正文 我和宋清朗相戀三年盼忌,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片掂墓。...
    茶點(diǎn)故事閱讀 38,747評(píng)論 1 341
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡谦纱,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出君编,到底是詐尸還是另有隱情跨嘉,我是刑警寧澤,帶...
    沈念sama閱讀 34,441評(píng)論 4 333
  • 正文 年R本政府宣布吃嘿,位于F島的核電站祠乃,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏兑燥。R本人自食惡果不足惜跳纳,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 40,072評(píng)論 3 317
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望贪嫂。 院中可真熱鬧寺庄,春花似錦、人聲如沸力崇。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 30,828評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)亮靴。三九已至馍盟,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間茧吊,已是汗流浹背贞岭。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 32,069評(píng)論 1 267
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留搓侄,地道東北人瞄桨。 一個(gè)月前我還...
    沈念sama閱讀 46,545評(píng)論 2 362
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像讶踪,于是被迫代替她去往敵國(guó)和親芯侥。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,658評(píng)論 2 350

推薦閱讀更多精彩內(nèi)容

  • CocoaPods簡(jiǎn)介 每種語(yǔ)言發(fā)展到一個(gè)階段,就會(huì)出現(xiàn)相應(yīng)的依賴(lài)管理工具柱查,例如Java語(yǔ)言的Maven廓俭,node...
    頂級(jí)蝸牛閱讀 359評(píng)論 0 1
  • CocoaPods 簡(jiǎn)介 它是iOS最常用的第三方庫(kù)依賴(lài)管理工具,且絕大多數(shù)優(yōu)秀的開(kāi)源框架都支持CocoaPods...
    Chars閱讀 1,276評(píng)論 1 20
  • 前言 在開(kāi)發(fā)項(xiàng)目的時(shí)候唉工,難免會(huì)導(dǎo)入一些三方開(kāi)源庫(kù)研乒,CocoaPods是OS X管理三方開(kāi)源庫(kù)的工具,用這個(gè)工具淋硝,我...
    WenBo丨星空灬閱讀 4,771評(píng)論 0 11
  • “這個(gè)世界上會(huì)寫(xiě)字的人太多告嘲, 但能給你帶來(lái)溫暖, 治愈你的奖地,卻太少橄唬。” 你的文字溫暖了我参歹,當(dāng)然仰楚,也刺痛過(guò)我,最后卻...
    一個(gè)笑靨如花的女子閱讀 527評(píng)論 0 0
  • 不知道為什么說(shuō)起北上廣犬庇,我卻總是想起海明威筆下的巴黎:“年輕人僧界,如果你足夠幸運(yùn)住在了巴黎,那么無(wú)論你在余生中會(huì)去哪...
    閆曉雨閱讀 405評(píng)論 2 6