cocoapods升级步骤
cocoapods升级步骤
很长一段时间未使用,更新不到最新的三方库,便要升级cocoapods
1、升级Ruby环境sudo gem update --system
2、更新cocoapods
sudo gem install -n /usr/local/bin cocoapods
3、更新repo
(这一步会比较漫长。。。)pod repo update
或是pod install --repo-update
cocoapods安装步骤
CocoaPods可以方便地通过Mac自带的RubyGems安装。
打开Mac电脑自带的终端,然后按照以下操作即可:
1.更换Ruby镜像
首先查看ruby当前源
$ gem sources -l
*** CURRENT SOURCES ***
https:
//rubygems.org/
移除ruby当前源
$ gem sources --remove https:
//rubygems.org/
替换国内最新镜像源(淘宝的Ruby镜像已经不更新了,https://gems.ruby-china.org域名更新为https://gems.ruby-china.com)
$ gem sources -a https:
//gems.ruby-china.com/
再次查看
$ gem sources -l
*** CURRENT SOURCES ***
https:
//gems.ruby-china.org
2.升级ruby环境
如果使用 $ gem update --system
会报错误
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory
这时使用
$ sudo gem update --system
升级成功后会提示
RubyGems system software updated
3.安装cocoapods
如果使用 $ sudo gem install cocoapods
报错误
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory
那就使用
$ sudo gem install -n /usr/local/bin cocoapods
然后执行pod setup (ps:这个执行很慢,耐心等待...... pod setup在执行时,会输出Setting up CocoaPods master repo,然后会卡一会儿。这步其实是 Cocoapods 将它的信息下载到 ~/.cocoapods目录下,你可以command+n
新建一个终端窗口,执行cd ~/.cocoapods/
进入到该文件夹下,然后du -sh *
查看文件大小,这个目录最终大小是900多M。出现Setup
completed 的时候说明已经完成了
$ pod setup
4.cocoapods使用
①首先搜索需要的三方库 AFNetworking,会出现符合条件的搜索结果
$ pod search AFNetworking
②在工程中创建Podfile文件,输入终端命令进入到工程目录下,然后创建Podfile文件
$ cd /Users/Desktop/YourAPPName
$ vim Podfile
③进入界面后,输入
platform :ios,
'8.0'
target
'YourApp'
do
pod
'AFNetworking'
,
'~> 3.1.0'
end
④把三方库下载到工程中
$ pod install
注:如果是在swift的工程中引入三方库,pod install 可能出现下面错误,处理办法
[!] The `GWeather [Debug]` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target Support Files/Pods-GWeather/Pods-GWeather.debug.xcconfig'. This can lead to problems with the CocoaPods installation - Use the `$(inherited)` flag, or - Remove the build settings from the target.
找到【Project/Target】-->【Your Project Name】-->【Buid Settings】
搜索‘ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES’,选择“other”,输入 $(inherited)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)