Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 307f9be

Browse files
新增CocoaPodsHook介绍
1 parent a9cc359 commit 307f9be

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

‎iOSNote/CocoaPods/CocoaPodsHook.md‎

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# CocoaPods Hook
2+
3+
> CocoaPods 会在其安装生命周期中提供各种 hook。这使用户可以自定义安装过程的多个时间点对其项目进行更改。
4+
5+
> hook方法还可以做一些其他语言脚本的执行,比如执行shell脚本,使用exec 后面跟上具体命令即可
6+
sh命令文件是一样的
7+
8+
9+
10+
## pre_install
11+
12+
> pod install 之前可以做一些其他处理
13+
14+
```
15+
pre_install do |installer|
16+
puts "pre install hook"
17+
Pod::UI.puts "pre install hook "
18+
end
19+
20+
```
21+
22+
## post_install
23+
24+
- pod install 之后可以做一些其他处理
25+
26+
```
27+
post_install do |installer|
28+
puts "post install hook"
29+
exec 'pwd'
30+
31+
end
32+
33+
34+
35+
post_install do |installer|
36+
# 遍历项目中所有target
37+
installer.pods_project.targets.each do |target|
38+
# 遍历build_configurations
39+
target.build_configurations.each do |config|
40+
# 修改build_settings中的ENABLE_BITCODE
41+
config.build_settings['ENABLE_BITCODE'] = 'NO'
42+
end
43+
end
44+
end
45+
46+
47+
# 开启 generate_multiple_pod_projects
48+
49+
post_install do |installer|
50+
installer.generated_projects.each do |project|
51+
project.targets.each do |target|
52+
target.build_configurations.each do |config|
53+
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '11.0'
54+
end
55+
end
56+
end
57+
end
58+
59+
60+
```
61+
62+
## post_integrate
63+
64+
> **1.10新增** 集成是安装过程的最后一步,它负责将生成的 Pods.xcodeproj 与用户的项目集成。这个 hook 将在完成后立即执行。
65+
66+
- 注意:这个 hook 在所有 .xcodeproj 保存(写入磁盘)之后执行。对 Pods.xcodeproj 进行更改将需要额外的 save 操作,但这可能会很慢。如果您预计在Pods.xcodeproj 保存到磁盘之前对其进行更改,则建议使用 post_install hook。
67+
68+
69+
```
70+
post_integrate do |installer|
71+
72+
puts "post_integrate hook"
73+
74+
end
75+
76+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /