macos下cocoapods的学习

发布于:2025-02-28 ⋅ 阅读:(10) ⋅ 点赞:(0)

step1:升级ruby

$ /bin/bash -c " $ (curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
$ brew update
$ brew install ruby
$ echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
$ export LDFLAGS="-L/usr/local/opt/ruby/lib"
$ export CPPFLAGS="-I/usr/local/opt/ruby/include"
$ export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"

step2: 升级环境/切换镜像

$ sudo gem update --system
$ gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
$ gem sources -l

step3: 安装cocoapods

$ sudo gem install cocoapods
$ pod install --verbose --no-repo-update #下载某库

step4:search不到lib

$ pod search AFNetworking
-bash: /usr/local/bin/pod: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby: bad interpreter: No such file or directory
解决办法:

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

step5: 编辑Podfile并执行

在xcodeproj文件所在目录下,创建Podfile,并编辑如下:

# way 1st
target :'CocoaPodsTest' do 
pod 'AFNetworking'
end
# way 2nd
platform :iOS, '8.0'
pod 'AFNetworking'
# way 3rd
platform :ios, '8.0'
target "TextDemo" do
pod 'AFNetworking'
end

在Podfile所在目录下执行

$ pod install

执行成功后,将出现.xcworkspace的文件,用xcode从此打开项目。

原文链接:

https://www.cnblogs.com/hecanlin/p/13297480.html
https://zhuanlan.zhihu.com/p/22986192
https://zhuanlan.zhihu.com/p/269772076