cocoapods的使用

转载必须声明出处,谢谢!

网上的教程都比较旧了,有各种问题这是我2023年6月左右写的安装办法,算是最新的咯

1.首先你必须跟上时代,在工程中用上cocoapods(网络上也可以搜到很多安装教程,这里要注意的是原来的http换成了https)

打开mac终端(Terminal),依次输入这四行命令:

#查看原来的源
gem sources -l


#使用清华的镜像
gem sources --add https://mirrors.tuna.tsinghua.edu.cn/rubygems/ --remove https://gems.ruby-china.com
 

#查看新的源
gem sources -l

#安装
sudo gem install cocoapods

2.安装完cocoapods后,创建一个新的工程,然后在工程的根目录也就是有 .xcodeproj 后缀的那个目录创建一个名字叫Podfile的文件(这个文件没有后缀)

在Podfile文件中写上常用的库,例如:

platform :ios, '8.0'

target :Inspiration do

    pod "AFNetworking","~> 2.6.3"
end

3.在终端(Terminal)中cd到Podfile文件的目录,然后运行pod install例如:

cd ~/Documents/xcode/workproject/Inspiration/  

pod install

pwd 可以查看当前路径

ls 可以查看当前目录下的文件列表

4.pod install后工程中就会出现一个后缀为.xcworkspace的文件,之后就用xcode打开这个文件而不是原来工程中的.xcodeproj文件了。

PS:更新:如果出现下方错误则需要更新库:

[!] CocoaPods could not find compatible versions for pod "IQKeyboardManager":
  In snapshot (Podfile.lock):
    IQKeyboardManager (= 4.0.11)

  In Podfile:
    IQKeyboardManager (~> 4.0.11)

None of your spec sources contain a spec satisfying the dependencies: `IQKeyboardManager (~> 4.0.11), IQKeyboardManager (= 4.0.11)`.

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.

Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by default.
// 移除本地master
sudo rm -fr ~/.cocoapods/repos/master
// 移除本地缓存
sudo rm -fr ~/Library/Caches/CocoaPods/
// 重新setup,如果网速较慢,可以在后面加上 --verbose
pod setup

// 更新到最新的预览版,一次到底
sudo gem install cocoapods --pre

如果sudo gem install cocoapods --pre 
无效才考虑移除本地缓存

重新安装ruby
 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值