腾讯云搭建网站

刚刚完成一半,简单记录目前的流程,等后续备案完成后再梳理一遍

一、本地开发静态站点

  • VS Code
  • 创建站点
  • 编辑以下:
    • html
    • css
    • js

二、购买腾讯云轻量应用服务器(Lighthouse)

  • 四百多一年即可

三、使用FTP客户端连接到云服务器

  • 公有IP
  • 端口号 21
  • user name
  • password
  • 很重要的是在连接过程中会使用到3000-4000这个范围内的端口,需要在云服务器的防火墙开启这些端口,不然本地电脑会连不上云服务器的FTP

四、备案

  • 明天继续写

Flutter开发

前言

本文介绍从iOS原生开发转向使用Flutter跨平台开发混编,包括:

  • 项目结构
  • iOS原生与flutter的通信
  • flutter的路由

1、Flutter介绍

Flutter是由Google推出的、使用Dart编程语言的跨平台开发框架。类似的跨平台框架还有Facebook于2015年推出的React Native。Dart可以直接编译为ARM代码和Fiasco微内核,且采用了Google自己的Skia渲染引擎(也被用于android)。React Native需要频繁地在JavaScript线程与原生线程之间切换上下文,性能方面有一定的影响。

与原生开发对比:

  • 优势:
    • 跨平台,节约开发成本;
    • 热重载
    • 编辑器VS Code有许多第三方插件,提升效率
  • 劣势:
    • 学习成本,需要重新学习Dart开发语言
    • 编程习惯,

Flutter版本管理:FVM

FVM(Flutter Version Management)是一款管理Flutter版本的工具,简化Flutter版本管理的流程。

  • 允许在一台机器上安装和使用多个Flutter版本
  • 可以指定某个项目使用特定的版本,有助于团队合作及CI/CD的稳定性
  • 支持版本切换

2、项目结构

这里使用VS Code作文编辑器

3、第三方框架

首先介绍GetX

4、与原生数据交互

App原生与跨平台开发

当下App开发可采用:1、原生开发(如android选择JavaKotliniOS可选择Objective-CSwift),2、跨平台开发(React NativeFlutter)。

由于笔者最近也接触跨平台开发,这里顺便介绍一下Flutter和React Native这两个当下非常热门的跨品台应用开发框架的对比,后续若要在二者间选型可简单参考。

1、首先主要关注性能方面:

  • Flutter是谷歌推出的框架,采用谷歌自家的Dart语言、拥有良好的性能,原因是Dart可以直接编译为ARM代码和Fiasco微内核并且使用自己的渲染引擎Skia。Skia同时也是Android系统的图形渲染引擎之一,iOS的渲染引擎有Quartz 2D、OpenGL ES、Metal、Core Animation、Core Image。
  • React Native需要在JavaScript线程和原生线程之间频繁切换上下文,对性能有一定的影响。

2、UI组件:

  • Flutter:
  • React Native:

3、开发语言:

  • Flutter:Google的Dart
  • React Native:Java Script

4、社区和生态:

  • Flutter:快速发展中
  • React Native:发布更早,有比较成熟的社区,插件和三方库较多。

5、热重载:二者都支持热重载,与原生相比可能快速地调试。

WordPress隐藏文章作者日期等信息

文章默认在标题下都会显示相关信息如:

post on by

如果决定这些不好看,希望移除它们,这里有一个很简单的方法:使用自定义css,具体步骤是:

访问WordPress后台,点击:外观 -> 自定义 -> 附加CSS

在编辑框中输入:

.entry-meta .byline, .entry-meta .cat-links { display: none; }
.entry-meta .posted-on { display: none; }

保存即可。

这样在发布的文章标题下就不会再显示发布时间作者了。

post on by hide

zsh自动填充插件zsh-autosuggestionszsh

brew安装

brew install zsh-autosuggestions

Logs:

Last login: Wed Mar  6 10:07:19 on ttys000
➜  ~ brew install zsh-autosuggestions
==> Downloading https://formulae.brew.sh/api/formula.jws.json
##O=-#     #
==> Downloading https://formulae.brew.sh/api/cask.jws.json
##O=-#     #
==> Downloading https://ghcr.io/v2/homebrew/core/zsh-autosuggestions/manifests/0.7.0-1
############################################################################################################################################################################## 100.0%
==> Fetching zsh-autosuggestions
==> Downloading https://ghcr.io/v2/homebrew/core/zsh-autosuggestions/blobs/sha256:4537653cbf3540a0785481966b36291255839f1be4012a22409ef97c46a1860b
############################################################################################################################################################################## 100.0%
==> Pouring zsh-autosuggestions--0.7.0.all.bottle.1.tar.gz
==> Caveats
To activate the autosuggestions, add the following at the end of your .zshrc:

  source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh

You will also need to restart your terminal for this change to take effect.
==> Summary
🍺  /opt/homebrew/Cellar/zsh-autosuggestions/0.7.0: 6 files, 44.8KB
==> Running `brew cleanup zsh-autosuggestions`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

根据上述提示,编辑~/.zshrc:在末尾追加

source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh

最后,使之生效

source ~/.zshrc

效果:

zsh高亮插件zsh-syntax-highlighting

brew安装

brew install zsh-syntax-highlighting

logs:

Last login: Tue Mar  5 15:41:48 on ttys000
➜  ~ brew install zsh-syntax-highlighting
==> Downloading https://formulae.brew.sh/api/formula.jws.json
############################################################################################################################################################################## 100.0%
==> Downloading https://formulae.brew.sh/api/cask.jws.json
############################################################################################################################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/zsh-syntax-highlighting/manifests/0.8.0
############################################################################################################################################################################## 100.0%
==> Fetching zsh-syntax-highlighting
==> Downloading https://ghcr.io/v2/homebrew/core/zsh-syntax-highlighting/blobs/sha256:603dabae4003cd3d95ab7f872a7fd9944e67cf0d963ffe42a07c8f3c191211ea
############################################################################################################################################################################## 100.0%
==> Pouring zsh-syntax-highlighting--0.8.0.arm64_sonoma.bottle.tar.gz
==> Caveats
To activate the syntax highlighting, add the following at the end of your .zshrc:
  source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

If you receive "highlighters directory not found" error message,
you may need to add the following to your .zshenv:
  export ZSH_HIGHLIGHT_HIGHLIGHTERS_DIR=/opt/homebrew/share/zsh-syntax-highlighting/highlighters
==> Summary
🍺  /opt/homebrew/Cellar/zsh-syntax-highlighting/0.8.0: 27 files, 203.4KB
==> Running `brew cleanup zsh-syntax-highlighting`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
➜  ~ 

根据上述提示,编辑~/.zshrc:在末尾追加

source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

最后,使之生效

source ~/.zshrc

效果:

使用之前
使用之前

使用之后
使用之后

Mac配置CocoaPods

本文介绍安装并使用CocoaPods

CocosPods的官网: https://www.cocoapods.org/

前言

CocoaPods是一个ruby gem,不知道具体是啥暂时也没关系~

安装CocoaPods的完整流程是:1、安装Homebrew -> 2、安装Ruby –> 3、安装并配置CocoaPods

三者之间有一个链式的依赖关系:Homebrew 用于安装 Ruby,然后 Ruby 用于运行 CocoaPods。

所以开始之前,我们先要了解两个东西,分别是Homebrew和Ruby。

1、Homebrew

官网:https://brew.sh/

Homebrew 是 Mac 操作系统上的一个包管理器,它可以让我们更方便地安装、更新和删除软件。Homebrew 可以用来安装 Ruby,也可以安装许多其他类型的软件。

安装Homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Logs:

Last login: Tue Mar  5 10:23:16 on ttys000
➜  ~ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
==> Checking for `sudo` access (which may request your password)...
Password:
==> This script will install:
/opt/homebrew/bin/brew
/opt/homebrew/share/doc/homebrew
/opt/homebrew/share/man/man1/brew.1
/opt/homebrew/share/zsh/site-functions/_brew
/opt/homebrew/etc/bash_completion.d/brew
/opt/homebrew

Press RETURN/ENTER to continue or any other key to abort:
==> /usr/bin/sudo /usr/sbin/chown -R rayvision:admin /opt/homebrew
==> Downloading and installing Homebrew...
remote: Enumerating objects: 1215, done.
remote: Counting objects: 100% (886/886), done.
remote: Compressing objects: 100% (270/270), done.
remote: Total 1215 (delta 648), reused 819 (delta 605), pack-reused 329
Receiving objects: 100% (1215/1215), 1.01 MiB | 1.88 MiB/s, done.
Resolving deltas: 100% (682/682), completed with 140 local objects.
From https://github.com/Homebrew/brew
 * [new branch]          build-cask-internal-json-v3 -> origin/build-cask-internal-json-v3
 * [new branch]          dependabot/bundler/Library/Homebrew/json_schemer-2.2.0 -> origin/dependabot/bundler/Library/Homebrew/json_schemer-2.2.0
   96f861e94..cf7c093b3  master     -> origin/master
 * [new branch]          memoize-installed-tap-loading -> origin/memoize-installed-tap-loading
 * [new branch]          sponsors-maintainers-man-completions -> origin/sponsors-maintainers-man-completions
 * [new tag]             4.2.10     -> 4.2.10
 * [new tag]             4.2.11     -> 4.2.11
HEAD is now at cf7c093b3 Merge pull request #16812 from cho-m/formula_auditor-also-check-tag
Updated 3 taps (homebrew/services, homebrew/core and homebrew/cask).
==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics data has been sent yet (nor will any be during this install run).

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations

==> Next steps:
- Run brew help to get started
- Further documentation:
    https://docs.brew.sh

if there is a Warning like:

 Warning: /opt/homebrew/bin is not in your PATH.
  Instructions on how to configure your shell for Homebrew
  can be found in the 'Next steps' section below.

Steps

Next steps:
- Run these two commands in your terminal to add Homebrew to your PATH:
    (echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/hsiao/.zprofile
    eval "$(/opt/homebrew/bin/brew shellenv)"

we should follow the steps with two command:

1、(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> /Users/hsiao/.zprofile

2、eval "$(/opt/homebrew/bin/brew shellenv)"

2、Ruby

官网:https://www.ruby-lang.org/en/

Ruby 是一种开源的编程语言,它易于理解和编写。CocoaPods 是用 Ruby 编写的一个gem,因此我们需要在计算机上安装 Ruby 才能使用 CocoaPods。

Mac系统自带的 Ruby 版本通常位于/usr/bin/ruby路径下,但自带的通常是较低版本,不建议用它来开发。建议同时安装最新版本的Ruby,并制定使用我们所安装的版本(当前最新版本为3.3.0)的 Ruby 版本进行开发。

我们可以采用rvm来管理多个不同版本的Ruby,就像flutter也可以使用fvm来管理。

查看默认的ruby:

/usr/bin/ruby -v

Logs:

ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin23]

使用homebrew安装ruby

brew install ruby

Logs:

Last login: Tue Mar  5 11:05:10 on ttys001
➜  ~ brew install ruby
==> Downloading https://ghcr.io/v2/homebrew/core/ruby/manifests/3.3.0
############################################################################################################################################################################## 100.0%
==> Fetching dependencies for ruby: libyaml, ca-certificates and openssl@3
==> Downloading https://ghcr.io/v2/homebrew/core/libyaml/manifests/0.2.5
############################################################################################################################################################################## 100.0%
==> Fetching libyaml
==> Downloading https://ghcr.io/v2/homebrew/core/libyaml/blobs/sha256:98c0cf81bcdf7577d5fdc8cc18732970b9ae7e0e7423a733f88f0f566ba483ad
############################################################################################################################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/ca-certificates/manifests/2023-12-12
############################################################################################################################################################################## 100.0%
==> Fetching ca-certificates
==> Downloading https://ghcr.io/v2/homebrew/core/ca-certificates/blobs/sha256:5c99ffd0861f01adc19cab495027024f7d890e42a9e7b689706b85c8e2b9c9b3
############################################################################################################################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/openssl/3/manifests/3.2.1-1
############################################################################################################################################################################## 100.0%
==> Fetching openssl@3
==> Downloading https://ghcr.io/v2/homebrew/core/openssl/3/blobs/sha256:fce7bf159988bf2b0960fa3d33ea810688d422c433b6461c7020cd0c937827a6
############################################################################################################################################################################## 100.0%
==> Fetching ruby
==> Downloading https://ghcr.io/v2/homebrew/core/ruby/blobs/sha256:f1df6988bf95afc9fd2f0f3c81f5ebbc44c329e0256e0cb9e6d1ff0afa87042c
############################################################################################################################################################################## 100.0%
==> Installing dependencies for ruby: libyaml, ca-certificates and openssl@3
==> Installing ruby dependency: libyaml
==> Downloading https://ghcr.io/v2/homebrew/core/libyaml/manifests/0.2.5
Already downloaded: /Users/rayvision/Library/Caches/Homebrew/downloads/5f6b0af1730aa1bc02f8021c90ed7ffe988eeba95eec83e6c828f77332ba6406--libyaml-0.2.5.bottle_manifest.json
==> Pouring libyaml--0.2.5.arm64_sonoma.bottle.tar.gz
🍺  /opt/homebrew/Cellar/libyaml/0.2.5: 10 files, 352.3KB
==> Installing ruby dependency: ca-certificates
==> Downloading https://ghcr.io/v2/homebrew/core/ca-certificates/manifests/2023-12-12
Already downloaded: /Users/rayvision/Library/Caches/Homebrew/downloads/13aa86e429e05d02a76005d1881eaf625091a5ac4dc7d7674c706d12ba48796a--ca-certificates-2023-12-12.bottle_manifest.json
==> Pouring ca-certificates--2023-12-12.all.bottle.tar.gz
==> Regenerating CA certificate bundle from keychain, this may take a while...
🍺  /opt/homebrew/Cellar/ca-certificates/2023-12-12: 3 files, 226.7KB
==> Installing ruby dependency: openssl@3
==> Downloading https://ghcr.io/v2/homebrew/core/openssl/3/manifests/3.2.1-1
Already downloaded: /Users/rayvision/Library/Caches/Homebrew/downloads/f7b6e249843882452d784a8cbc4e19231186230b9e485a2a284d5c1952a95ec2--openssl@3-3.2.1-1.bottle_manifest.json
==> Pouring openssl@3--3.2.1.arm64_sonoma.bottle.1.tar.gz
🍺  /opt/homebrew/Cellar/openssl@3/3.2.1: 6,874 files, 32MB
==> Installing ruby
==> Pouring ruby--3.3.0.arm64_sonoma.bottle.tar.gz
==> Caveats
By default, binaries installed by gem will be placed into:
  /opt/homebrew/lib/ruby/gems/3.3.0/bin

You may want to add this to your PATH.

ruby is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have ruby first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc

For compilers to find ruby you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/ruby/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/ruby/include"
==> Summary
🍺  /opt/homebrew/Cellar/ruby/3.3.0: 19,656 files, 51.4MB
==> Running `brew cleanup ruby`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
==> Caveats
==> ruby
By default, binaries installed by gem will be placed into:
  /opt/homebrew/lib/ruby/gems/3.3.0/bin

You may want to add this to your PATH.

ruby is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have ruby first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc

For compilers to find ruby you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/ruby/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/ruby/include"
➜  ~

⚠️注意:要将当前Ruby设置为默认版本,不然在下一步安装CocoaPods会报兼容性错误,因为默认ruby版本太低了

默认版本太低报错

ERROR:  Error installing cocoapods:
	The last version of drb (>= 0) to support your Ruby & RubyGems was 2.0.6. Try installing it with `gem install drb -v 2.0.6` and then running the current command again
	drb requires Ruby version >= 2.7.0. The current ruby version is 2.6.10.210.

配置ruby到$PATH环境变量,默认使用当前最新版

echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc
echo 'export LDFLAGS="-L/opt/homebrew/opt/ruby/lib"' >> ~/.zshrc
echo 'export CPPFLAGS="-I/opt/homebrew/opt/ruby/include"' >> ~/.zshrc
source ~/.zshrc

查看当前使用的Ruby版本

login: Tue Mar  5 11:18:48 on ttys002
➜  ~ ruby -v
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]

🏅没错,当前已经使用我们所安装的最新Ruby,版本是3.3.0。

接下来安装CocoaPods

3、CocoaPods

官网:https://www.cocoapods.org/

安装CocoaPods

sudo gem install cocoapods

Logs:

~ sudo gem install cocoapods
Password:
Fetching nanaimo-0.3.0.gem
Fetching colored2-3.1.2.gem
Fetching claide-1.1.0.gem
Fetching CFPropertyList-3.0.7.gem
Fetching atomos-0.1.3.gem
Fetching xcodeproj-1.24.0.gem
Fetching ruby-macho-2.5.1.gem
Fetching nap-1.1.0.gem
Fetching molinillo-0.8.0.gem
Fetching gh_inspector-1.1.3.gem
Fetching fourflusher-2.3.1.gem
Fetching escape-0.0.4.gem
Fetching cocoapods-try-1.2.0.gem
Fetching netrc-0.11.0.gem
Fetching cocoapods-trunk-1.6.0.gem
Fetching cocoapods-search-1.0.1.gem
Fetching cocoapods-plugins-1.0.0.gem
Fetching cocoapods-downloader-2.1.gem
Fetching cocoapods-deintegrate-1.0.5.gem
Fetching ffi-1.16.3.gem
Fetching ethon-0.16.0.gem
Fetching typhoeus-1.4.1.gem
Fetching public_suffix-4.0.7.gem
Fetching fuzzy_match-2.0.4.gem
Fetching concurrent-ruby-1.2.3.gem
Fetching httpclient-2.8.3.gem
Fetching algoliasearch-1.27.5.gem
Fetching addressable-2.8.6.gem
Fetching tzinfo-2.0.6.gem
Fetching i18n-1.14.1.gem
Fetching connection_pool-2.4.1.gem
Fetching activesupport-7.1.3.2.gem
Fetching cocoapods-1.15.2.gem
Fetching cocoapods-core-1.15.2.gem
Successfully installed nanaimo-0.3.0
Successfully installed colored2-3.1.2
Successfully installed claide-1.1.0
Successfully installed CFPropertyList-3.0.7
Successfully installed atomos-0.1.3
Successfully installed xcodeproj-1.24.0
Successfully installed ruby-macho-2.5.1
Successfully installed nap-1.1.0
Successfully installed molinillo-0.8.0
Successfully installed gh_inspector-1.1.3
Successfully installed fourflusher-2.3.1
Successfully installed escape-0.0.4
Successfully installed cocoapods-try-1.2.0
Successfully installed netrc-0.11.0
Successfully installed cocoapods-trunk-1.6.0
Successfully installed cocoapods-search-1.0.1
Successfully installed cocoapods-plugins-1.0.0
Successfully installed cocoapods-downloader-2.1
Successfully installed cocoapods-deintegrate-1.0.5
Building native extensions. This could take a while...
Successfully installed ffi-1.16.3
Successfully installed ethon-0.16.0
Successfully installed typhoeus-1.4.1
Successfully installed public_suffix-4.0.7
Successfully installed fuzzy_match-2.0.4
Successfully installed concurrent-ruby-1.2.3
Successfully installed httpclient-2.8.3
A new major version is available for Algolia! Please now use the https://rubygems.org/gems/algolia gem to get the latest features.
Successfully installed algoliasearch-1.27.5
Successfully installed addressable-2.8.6
Successfully installed tzinfo-2.0.6
Successfully installed i18n-1.14.1
Successfully installed connection_pool-2.4.1
Successfully installed activesupport-7.1.3.2
Successfully installed cocoapods-core-1.15.2
Successfully installed cocoapods-1.15.2
Parsing documentation for nanaimo-0.3.0
Installing ri documentation for nanaimo-0.3.0
Parsing documentation for colored2-3.1.2
Installing ri documentation for colored2-3.1.2
Parsing documentation for claide-1.1.0
Installing ri documentation for claide-1.1.0
Parsing documentation for CFPropertyList-3.0.7
Installing ri documentation for CFPropertyList-3.0.7
Parsing documentation for atomos-0.1.3
Installing ri documentation for atomos-0.1.3
Parsing documentation for xcodeproj-1.24.0
Installing ri documentation for xcodeproj-1.24.0
Parsing documentation for ruby-macho-2.5.1
Installing ri documentation for ruby-macho-2.5.1
Parsing documentation for nap-1.1.0
Installing ri documentation for nap-1.1.0
Parsing documentation for molinillo-0.8.0
Installing ri documentation for molinillo-0.8.0
Parsing documentation for gh_inspector-1.1.3
Installing ri documentation for gh_inspector-1.1.3
Parsing documentation for fourflusher-2.3.1
Installing ri documentation for fourflusher-2.3.1
Parsing documentation for escape-0.0.4
Installing ri documentation for escape-0.0.4
Parsing documentation for cocoapods-try-1.2.0
Installing ri documentation for cocoapods-try-1.2.0
Parsing documentation for netrc-0.11.0
Installing ri documentation for netrc-0.11.0
Parsing documentation for cocoapods-trunk-1.6.0
Installing ri documentation for cocoapods-trunk-1.6.0
Parsing documentation for cocoapods-search-1.0.1
Installing ri documentation for cocoapods-search-1.0.1
Parsing documentation for cocoapods-plugins-1.0.0
Installing ri documentation for cocoapods-plugins-1.0.0
Parsing documentation for cocoapods-downloader-2.1
Installing ri documentation for cocoapods-downloader-2.1
Parsing documentation for cocoapods-deintegrate-1.0.5
Installing ri documentation for cocoapods-deintegrate-1.0.5
Parsing documentation for ffi-1.16.3
Installing ri documentation for ffi-1.16.3
Parsing documentation for ethon-0.16.0
Installing ri documentation for ethon-0.16.0
Parsing documentation for typhoeus-1.4.1
Installing ri documentation for typhoeus-1.4.1
Parsing documentation for public_suffix-4.0.7
Installing ri documentation for public_suffix-4.0.7
Parsing documentation for fuzzy_match-2.0.4
Installing ri documentation for fuzzy_match-2.0.4
Parsing documentation for concurrent-ruby-1.2.3
Installing ri documentation for concurrent-ruby-1.2.3
Parsing documentation for httpclient-2.8.3
Installing ri documentation for httpclient-2.8.3
Parsing documentation for algoliasearch-1.27.5
Installing ri documentation for algoliasearch-1.27.5
Parsing documentation for addressable-2.8.6
Installing ri documentation for addressable-2.8.6
Parsing documentation for tzinfo-2.0.6
Installing ri documentation for tzinfo-2.0.6
Parsing documentation for i18n-1.14.1
Installing ri documentation for i18n-1.14.1
Parsing documentation for connection_pool-2.4.1
Installing ri documentation for connection_pool-2.4.1
Parsing documentation for activesupport-7.1.3.2
Couldn't find file to include 'activesupport/README.rdoc' from lib/active_support.rb
Installing ri documentation for activesupport-7.1.3.2
Parsing documentation for cocoapods-core-1.15.2
Installing ri documentation for cocoapods-core-1.15.2
Parsing documentation for cocoapods-1.15.2
Installing ri documentation for cocoapods-1.15.2
Done installing documentation for nanaimo, colored2, claide, CFPropertyList, atomos, xcodeproj, ruby-macho, nap, molinillo, gh_inspector, fourflusher, escape, cocoapods-try, netrc, cocoapods-trunk, cocoapods-search, cocoapods-plugins, cocoapods-downloader, cocoapods-deintegrate, ffi, ethon, typhoeus, public_suffix, fuzzy_match, concurrent-ruby, httpclient, algoliasearch, addressable, tzinfo, i18n, connection_pool, activesupport, cocoapods-core, cocoapods after 10 seconds
34 gems installed

A new release of RubyGems is available: 3.5.4 → 3.5.6!
Run `gem update --system 3.5.6` to update your installation.

➜  ~

安装过程结束,接下来我们需要初始化pod,这个过程会设置master repo,也就是配置默认的源,但是这个过程也可能异常,稍后会介绍。

初始化pod

pod setup

🤯Oops,发生了一个意外:

zsh:command not found:pod

这个错误通常表示pod命令没有被正确添加到当前的$PATH环境变量中,也就是说,系统找不到pod命令的位置。

我们是通过gem install cocoapods命令安装的 CocoaPods,那么 pod 命令应该位于 Ruby Gems 的bin目录中。但这个目录可能没有被加入到$PATH环境变量中,因此需要手动添加。

依然以 zsh 为例,你需要做的是,打开~/.zshrc文件,然后添加下面这一行:

export PATH="$PATH:$(gem env gemdir)/bin"

或者使用命令行:

echo 'export PATH="$PATH:$(gem env gemdir)/bin"' >> ~/.zshrc
source ~/.zshrc

然后重新打开终端。

查验一下是否已经添加到环境变量中:

cat ~/.zshrc

export PATH="/user/local/bin:$PATH"
export PATH="/opt/homebrew/opt/ruby/bin:$PATH"
export LDFLAGS="-L/opt/homebrew/opt/ruby/lib"
export CPPFLAGS="-I/opt/homebrew/opt/ruby/include"
export PATH="$PATH:$(gem env gemdir)/bin"

包含了export PATH="$PATH:$(gem env gemdir)/bin"就能使用pod指令了。

继续完成初始化工作

pod setup
Setup completed

使用Pod的搜索功能

pod search AFNetworking

搜索遇到问题:

Setup completed
[!]Unable to find a pod with name, author, summary, or description matching 'AFNetworking'

针对该问题,网络上一种

方案A:是认为是search缓存导致的,解决方案:

rm ~/Library/Caches/CocoaPods/search_index.json

实测无效🙅。另一种

方案B:是不管当前问题,直接使用Xcode创建一个iOS项目,并使用pod随便引用一个三方库如AFNetworking,最后执行pod install完成之后,再回到这里就能正常使用pod search功能。本文没尝试这种方案。。。

那该怎么解决呢?先看看pod环境

pod env

Logs:

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

解决方案是:

sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer

其实这里补充很关键的一点是,首先,确保已经安装了 Xcode 和 Xcode 命令行工具。如果没有,请在 App Store 中下载并安装 Xcode,并打开终端输入以下命令以安装 Xcode 命令行工具:

xcode-select --install

最后我们再次检查pod环境:pod env,好了,环境已经没有问题了。

  ~ pod env

### Stack

```
   CocoaPods : 1.15.2
        Ruby : ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
    RubyGems : 3.5.4
        Host : macOS 14.3.1 (23D60)
       Xcode : 15.2 (15C500b)
         Git : git version 2.39.3 (Apple Git-145)
Ruby lib dir : /opt/homebrew/Cellar/ruby/3.3.0/lib
Repositories :
```

### Installation Source

```
Executable Path: /opt/homebrew/lib/ruby/gems/3.3.0/bin/pod
```

### Plugins

```
cocoapods-deintegrate : 1.0.5
cocoapods-plugins     : 1.0.0
cocoapods-search      : 1.0.1
cocoapods-trunk       : 1.6.0
cocoapods-try         : 1.2.0

到这一步,pod环境已经正常,但在此使用pod的搜索功能还是报错找不到对应的库。

我们查看一下本地已添加的私有仓库

pod repo

😧发现竟然一个都没有:

0 repos

这意味着没有本地仓库,那我们可以使用pod repo add命令添加一个私有仓库。例如,执行pod repo add <repo-name> <repo-url>来添加一个私有仓库。

这里添加官方私有仓库

pod repo add cocoapods https://github.com/CocoaPods/Specs.git

Logs

Cloning spec repo `cocoapods` from `https://github.com/CocoaPods/Specs.git`

这个过程需要等待一段时间⏳,指令结束后我们再次查看本地似有仓库,看到已经包含官方私有仓库了:

pod repo

cocoapods
- Type: git (remotes/origin/master)
- URL:  https://github.com/CocoaPods/Specs.git
- Path: /Users/rayvision/.cocoapods/repos/cocoapods

📌也有安装清华大学的私有仓库,但是本文主打一个能够科学上网、所以未采用该方案。

使用清华源:

pod repo add tuna https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git

[清华源]:https://mirrors.tuna.tsinghua.edu.cn/help/CocoaPods/

安装过程终于快收尾了,再来试试搜索功能:

pod search AFNetworking

没想到还是报一样的错误❌,找不到!!!

😊其实到这里重开一遍终端再次执行搜索指令,就能正常工作了。

或者在设置官方私有仓库之后执行:

pod repo update --verbose