Mac上安装和设置Cocoapods
sudo gem install cocoapods
# 如果不成功,根据错误提示输入指令
ERROR: Error installing cocoapods:
The last version of activesupport (>= 5.0, < 8) to support your Ruby & RubyGems was 6.1.7.3. Try installing it with `gem install activesupport -v 6.1.7.3` and then running the current command again
activesupport requires Ruby version >= 2.7.0. The current ruby version is 2.6.10.210.
# 我这个输入的是
sudo gem install activesupport -v 6.1.7.3
# 重新输入安装指令
sudo gem install cocoapods
# 查看
pod setup --verbose
Ignoring iStats-1.6.1 because its extensions are not built. Try: gem pristine iStats --version 1.6.1
Setup completed
# 根据提示修复下,无关紧要
sudo gem pristine iStats --version 1.6.1
Ignoring iStats-1.6.1 because its extensions are not built. Try: gem pristine iStats --version 1.6.1
Restoring gems to pristine condition...
Building native extensions. This could take a while...
Restored iStats-1.6.1
# 再查看
pod setup --verbose
# 显示如下,OK
Setup completed
Xcode项目中安装Pods
(base) zhao@047c161b27b7 ~ % cd /Users/zhaowang/Desktop/SwiftProjects/dependenceTest
(base) zhao@047c161b27b7 dependenceTest % ls
dependenceTest dependenceTestTests
dependenceTest.xcodeproj dependenceTestUITests
(base) zhao@047c161b27b7 dependenceTest % pod init
(base) zhao@047c161b27b7 dependenceTest % ls
Podfile dependenceTest.xcodeproj dependenceTestUITests
dependenceTest dependenceTestTests
(base) zhao@047c161b27b7 dependenceTest % open -a Xcode Podfile
# ========================原本生成的文件如下
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'dependenceTest' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for dependenceTest
target 'dependenceTestTests' do
inherit! :search_paths
# Pods for testing
end
target 'dependenceTestUITests' do
# Pods for testing
end
end
# ========================修改后如下
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
target 'dependenceTest' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for dependenceTest
# expamle for weather
pod 'SwiftyJSON'
pod 'Alamofire'
pod 'SVProgressHUD'
target 'dependenceTestTests' do
inherit! :search_paths
# Pods for testing
end
target 'dependenceTestUITests' do
# Pods for testing
end
end
回到终端继续操作
(base) zhao@047c161b27b7 dependenceTest % pod --version
1.12.1
(base) zhao@047c161b27b7 dependenceTest % pod install
Analyzing dependencies
# 估计网络问题,下载不下来,尝试使用代理
# 在终端启用代理后,使用命令调用 Xcode 的 SPM 执行更新
# 打开终端,给当前终端会话设置代理环境,命令如下
export https_proxy=http://127.0.0.1:7890
export http_proxy=http://127.0.0.1:7890
export all_proxy=socks5://127.0.0.1:7890
# 继续在当前终端中使用 xcodebuild 命令来解析和更新 Swift Package依赖关系
xcodebuild -resolvePackageDependencies
# 使用 export 配置的代理设置仅对当前终端会话有效,不在同一个终端使用 xcodebuild,代理设置将失效。
(base) zhao@047c161b27b7 dependenceTest % export https_proxy=http://127.0.0.1:7890
export http_proxy=http://127.0.0.1:7890
export all_proxy=socks5://127.0.0.1:7890
# 继续安装
(base) zhao@047c161b27b7 dependenceTest % pod install
# 这次OK了
Analyzing dependencies
Downloading dependencies
Installing Alamofire (5.6.4)
Installing SVProgressHUD (2.2.5)
Installing SwiftyJSON (5.0.1)
Generating Pods project
Integrating client project
# 这边反馈提示说要重启Xcode,那就重启一下吧
[!] Please close any current Xcode sessions and use `dependenceTest.xcworkspace` for this project from now on.
Pod installation complete! There are 3 dependencies from the Podfile and 3 total pods installed.
[!] Automatically assigning platform `iOS` with version `16.2` on target `dependenceTest` because no platform was specified. Please specify a platform for this target in your Podfile. See `https://guides.cocoapods.org/syntax/podfile.html#platform`.
[!] The `dependenceTestUITests [Debug]` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target Support Files/Pods-dependenceTest-dependenceTestUITests/Pods-dependenceTest-dependenceTestUITests.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
[!] The `dependenceTestUITests [Release]` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target Support Files/Pods-dependenceTest-dependenceTestUITests/Pods-dependenceTest-dependenceTestUITests.release.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
# 升级库的话
pod update