2019安装cocoaPods

天大地大妈咪最大 提交于 2020-12-18 04:31:09

检索关键词:2019 CocoaPods使用

 

查看版本:gem --version

输出: 2.7.7

 

更换Ruby 源:

gem sources --remove https://rubygems.org/

gem sources --add https://gems.ruby-china.com/

淘宝的源好像不能用了用这个:https://gems.ruby-china.com/

 

安装cocoapods:   sudo gem install cocoapods

报错:

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /usr/bin directory.

输入:   sudo gem install -n /usr/local/bin cocoapods

输出:

Successfully installed httpclient-2.8.3
Fetching: algoliasearch-1.27.1.gem (100%)
Successfully installed algoliasearch-1.27.1
Fetching: cocoapods-core-1.8.4.gem (100%)
Successfully installed cocoapods-core-1.8.4
Fetching: cocoapods-deintegrate-1.0.4.gem (100%)
Successfully installed cocoapods-deintegrate-1.0.4
Fetching: cocoapods-downloader-1.3.0.gem (100%)
Successfully installed cocoapods-downloader-1.3.0
Fetching: cocoapods-trunk-1.4.1.gem (100%)
Successfully installed cocoapods-trunk-1.4.1
Fetching: molinillo-0.6.6.gem (100%)
Successfully installed molinillo-0.6.6
Fetching: atomos-0.1.3.gem (100%)
Successfully installed atomos-0.1.3
Fetching: xcodeproj-1.13.0.gem (100%)
Successfully installed xcodeproj-1.13.0
Fetching: fourflusher-2.3.1.gem (100%)
Successfully installed fourflusher-2.3.1
Fetching: ruby-macho-1.4.0.gem (100%)
Successfully installed ruby-macho-1.4.0
Fetching: cocoapods-1.8.4.gem (100%)
Successfully installed cocoapods-1.8.4
Parsing documentation for httpclient-2.8.3
Installing ri documentation for httpclient-2.8.3
Parsing documentation for algoliasearch-1.27.1
Installing ri documentation for algoliasearch-1.27.1
Parsing documentation for cocoapods-core-1.8.4
Installing ri documentation for cocoapods-core-1.8.4
Parsing documentation for cocoapods-deintegrate-1.0.4
Installing ri documentation for cocoapods-deintegrate-1.0.4
Parsing documentation for cocoapods-downloader-1.3.0
Installing ri documentation for cocoapods-downloader-1.3.0
Parsing documentation for cocoapods-trunk-1.4.1
Installing ri documentation for cocoapods-trunk-1.4.1
Parsing documentation for molinillo-0.6.6
Installing ri documentation for molinillo-0.6.6
Parsing documentation for atomos-0.1.3
Installing ri documentation for atomos-0.1.3
Parsing documentation for xcodeproj-1.13.0
Installing ri documentation for xcodeproj-1.13.0
Parsing documentation for fourflusher-2.3.1
Installing ri documentation for fourflusher-2.3.1
Parsing documentation for ruby-macho-1.4.0
Installing ri documentation for ruby-macho-1.4.0
Parsing documentation for cocoapods-1.8.4
Installing ri documentation for cocoapods-1.8.4
Done installing documentation for httpclient, algoliasearch, cocoapods-core, cocoapods-deintegrate, cocoapods-downloader, cocoapods-trunk, molinillo, atomos, xcodeproj, fourflusher, ruby-macho, cocoapods after 13 seconds
12 gems installed

 

查看pod版本:pod --version

输出:1.8.4

 

cd到项目目录,

创建podfile:   touch Podfile,

在podfile填入内容:

source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '8.0'

target 'test' do
 pod 'SDWebImage'
end

 

安装SDWebImage: pod install,注意,podfile里面的注释不是//,双斜线pod install会报错

 

pod install 报错:

CDN: trunk URL couldn't be downloaded: https://raw.githubusercontent.com/CocoaPods/Specs/master/Specs/1/1/7/SDWebImage/5.4.0/SDWebImage.podspec.json, error: Failed to open TCP connection to raw.githubusercontent.com:443 (Connection refused - connect(2) for "raw.githubusercontent.com" port 443)

在podfile最上面添加  source 'https://github.com/CocoaPods/Specs.git':

source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '8.0'

target 'test' do
 pod 'SDWebImage'

end

 

再次 pod install, 报错:

[!] CocoaPods could not find compatible versions for pod "SDWebImage":
  In Podfile:
    SDWebImage (~> 5.0)

None of your spec sources contain a spec satisfying the dependency: `SDWebImage (~> 5.0)`.

You have either:
 * out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`.
 * mistyped the name or version.
 * not added the source repo that hosts the Podspec to your Podfile.

修改pod file,去掉sdwebimage指定的版本号:

pod 'SDWebImage'

然后pod install

安装成功,重启xcode,运行OK

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!