Skip to content

Commit

Permalink
update cocoapods doc
Browse files Browse the repository at this point in the history
  • Loading branch information
DevDragonLi committed May 22, 2021
1 parent d15b98f commit 7ff3b21
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 235 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
|iOS技能图谱/技术栈|[iOS技能图谱-byStuQ](./iOSNote/map-MobileDev-iOSDev.md) <br>[JSPatch作者博客中的技能栈-图](./images/iOS/iOSDev-bang.png)|
|iOS开发相关shell脚本|[Pod自动化更新脚本&&组件校验脚本](https://github.com/DevDragonLi/DevelopBaseNote#shell)<br>[项目依赖子组件批量更新克隆脚本](https://github.com/DevDragonLi/DevelopBaseNote#shell)|
|iOSDevNote|[**东半球效率最高的iOS组件通信中间件**](https://github.com/DevDragonLi/ProtocolServiceKit)<br>[**DarkMode适配组件**](https://github.com/DevDragonLi/LFLDarkModeKit)<br>[iOS项目完全解耦**Debug菜单中心组件**](https://github.com/DevDragonLi/iOSDebugKit)<br>[**iOS开发架构分享文稿**](./iOSNote/iOS_architecture.pdf)<br>[**掘金客户端体积瘦身**](./iOSNote/iOSAppThin.md)<br>[**iOSDevCodeRepo**](https://github.com/DevDragonLi/iOSDevDemo)<br>[Core Animation框架结构及性能调优11张大图详解](https://github.com/DevDragonLi/Core-AnimationPerformanceOptimization)<br>[iOS_StaticLibrary](./iOSNote/iOS_StaticLibrary.md)<br>[iOS经典Crash分析与总结- QQ`MelonTeam`](https://github.com/DevDragonLi/iOSDevDemo)<br>[iOS核心动画高级技巧阅读笔记(**性能调优**,**高效绘制**,**图像IO**,**图层性能**)](./iOSNote/iOSCoreAnimationNote.md)<br>[单元测试概述](./iOSNote/UnitTesting.md)|
|CocoaPods 相关 |[**cocoapods-plugins**](./iOSNote/CocoaPods/cocoapods-plugins.md)<br>[提交开源框架之流程](./iOSNote/CocoaPods/cocoapods-podspec.md)<br>[管理库的使用技巧](./iOSNote/CocoaPods/cocoapods-podspec.md)<br>[私有源组件化及podfile总结](./iOSNote/CocoaPods/Podfile.md)<br>[私有库参考Demo](https://github.com/DevDragonLi/iOSDevDemo/tree/master/1-DevDemo/PodPrivate_demo)<br>[podspec总结](./iOSNote/CocoaPods/podspec.md)|
|CocoaPods |[**cocoapods-plugins:插件汇总**](./iOSNote/CocoaPods/cocoapods-plugins.md)<br>[开源组件之开发流程](./iOSNote/CocoaPods/cocoapods-pod.md)<br>[管理库的使用技巧](./iOSNote/CocoaPods/cocoapods-pod.md)<br>[公司内部组件化开发参考基础文档](./iOSNote/CocoaPods/cocoapods-PodFile&spec.md)<br>[私有库参考Demo](https://github.com/DevDragonLi/iOSDevDemo/tree/master/1-DevDemo/PodPrivate_demo)<br>[Podspec语法说明及PodFile使用汇总](./iOSNote/CocoaPods/cocoapods-PodFile&spec.md)|
|开源框架|**[WiFi显示图片高清图;蜂窝显示图片缩略图解析](./iOSNote/Analyze/SDWebImage/网络网络状态不同加载图片.md)**<br>**[MJRefresh源码解析](./iOSNote/Analyze/MJRefresh/MJRefresh.md)**|

## 赞赏一下旺仔(收集整理不易,且赞且珍惜)
Expand Down
115 changes: 0 additions & 115 deletions iOSNote/CocoaPods/Podfile.md

This file was deleted.

213 changes: 213 additions & 0 deletions iOSNote/CocoaPods/cocoapods-PodFile&spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
# PodFile&&Podspec

## base

- **cocoapods**: **/Users/`LFL`/.cocoapods/repos**

- **cache**: **/Users/`LFL`/Library/Caches/CocoaPods/** 包含如下
- pods :缓存已经安装的第三方
- search_index.json


## Podspec

```ruby
s.name:名称,pod search 搜索的关键词
s.version:版本 (tag)
s.summary:pod search 搜索的关键词
s.homepage:主页地址,例如Github地址
s.license:许可证
s.author:作者
s.social_media_url:社交网址
s.platform:平台
s.source:Git仓库地址,例如在Github地址后边加上 .git 就是Git仓库地址.
s.source_files :"ProjectKit/*"
* `*` 表示匹配所有文件:"ProjectKit/*"
* `*.{h,m}` 表示匹配所有以.h和.m结尾的文件:"ProjectKit/Classes/*.{h,m}"
* `**` 表示匹配所有`子目录`:"ProjectKit/**/*.h"

s.resources:需要包含的图片等资源文件
s.dependency:依赖库,如有多个可以这样写,需要用到的frameworks,不需要加.frameworks后缀
s.requires_arc:是否要求ARC

```

- **资源文件**
- `Assets` 文件夹内图片资源最终会打包成一个 `bundle` 文件

```
图片bundle 资源
[[NSbundle bundleForClass :self] pathForResource:"" inDirectory:"当前pod库名.bundle"]
cell : xib
cell = [[[NSBundle bundleForClass:self] loadNibNamed:@"cell 对应 name " owner:nil options:nil] firstObject];
cell 使用图片:`当前pod库名.bundle/图片名`,不能再使用[UIImage imageName:@"名字"],使用 contenofURL
```
- **xib 处理**
- 先编译为 `nib`
- 读取涉及图片,需要处理对应的`@2`,`@3`


- **子库分离 参考 "AFN"**


`s.subspec 'LFLSegumentTool' do |b|
b.source_files => 'LFLTest/LFLSegumentTool/*'
子库依赖单独处理
b.dependecy = 'GitHubSegumentTool'
end`


### PodFile

- 指定多个子库

```
pod `LFLKit`,:subspec =>['base','LFLTool']

```

- 如果您的Pods文件夹不包含在git中,则您可以添加keep_source_code_for_prebuilt_frameworks!Podfile的头部以加快Pod的安装速度,因为每次预建的Pod发生更改时,它都不会下载所有源代码。

- enable_bitcode_for_prebuilt_frameworks!

```ruby
要使用仓库的另一个分支:

pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'dev'

要使用master仓库的分支:

pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git'

/// 指定固定源
pod 'PonyDebugger', :source => 'https://github.com/CocoaPods/Specs.git'

pod 'QueryKit', :subspecs => ['Attribute', 'QuerySet']

pod "test",:head 一直最新

```

- Build configurations

```ruby
pod 'PonyDebugger', :configurations => ['Debug', 'Beta']

pod 'PonyDebugger', :configuration => 'Debug'

```

### generate_multiple_pod_projects


- `install! 'cocoapods', generate_multiple_pod_projects: true`

- 多个兼容

```ruby
install! 'cocoapods',
disable_input_output_paths: true,
generate_multiple_pod_projects: true

```

```ruby

post_install do |installer|

swift_4_0_compatible = [ ... ]
swift_4_2_compatible = [ ... ]

installer.pod_target_subprojects.flat_map { |p| p.targets }.each do |t|
t.build_configurations.each do |c|
c.build_settings['SWIFT_VERSION'] = '4.0' if swift_4_0_compatible.include? t.name
c.build_settings['SWIFT_VERSION'] = '4.2' if swift_4_2_compatible.include? t.name
end
end
end

```
## PodSpec 扩展

> https://guides.cocoapods.org/syntax/podspec.html
- s.static_framework = true
- 是否是静态库 这个地方很重要 假如不写这句打出来的包 就是动态库 不能使用 一运行会报错 image not found

- spec.swift_version = '3.0', '4.0'

- spec.cocoapods_version = '>= 0.36'

- spec.prepare_command = 'ruby build_files.rb'

- spec.dependency 'AFNetworking', '~> 1.0', :configurations => ['Debug']

- spec.prefix_header_contents = '#import <UIKit/UIKit.h>', '#import <Foundation/Foundation.h>'


```ruby

spec.prefix_header_file = 'iphone/include/prefix.pch'
spec.prefix_header_file = false

spec.module_name = 'Three20'

# 配置 Xcode Build Setting
s.xcconfig = {
'HEADER_SEARCH_PATHS' => '$(PODS_ROOT)/', # 配置 Header 搜索路径
'FRAMEWORK_SEARCH_PATHS' => '$(PODS_ROOT)/', # 配置 Framwork 搜索路径
'GCC_PREPROCESSOR_DEFINITIONS' => 'RELEASE COCOAPODS=1' # 配置预编译宏
}

```

```ruby
spec.ios.vendored_frameworks = 'Frameworks/MyFramework.framework'
spec.vendored_frameworks = 'MyFramework.framework', 'TheirFramework.framework'

spec.ios.vendored_library = 'Libraries/libProj4.a'
spec.vendored_libraries = 'libProj4.a', 'libJavaScriptCo
spec.ios.resource_bundle = { 'MapBox' => 'MapView/Map/Resources/*.png' }
spec.resource_bundles = {
'MapBox' => ['MapView/Map/Resources/*.png'],
'MapBoxOtherResources' => ['MapView/Map/OtherResources/*.png']
}
spec.resource = 'Resources/HockeySDK.bundle'
spec.resources = ['Images/*.png', 'Sounds/*']
spec.default_subspec = 'Core'
spec.default_subspecs = 'Core', 'UI'
spec.default_subspecs = :none
```
```ruby
Pod::Spec.new do |spec|
spec.name = 'ShareKit'
spec.source_files = 'Classes/ShareKit/{Configuration,Core,Customize UI,UI}/**/*.{h,m,c}'
# ...
spec.subspec 'Evernote' do |evernote|
evernote.source_files = 'Classes/ShareKit/Sharers/Services/Evernote/**/*.{h,m}'
end
spec.subspec 'Facebook' do |facebook|
facebook.source_files = 'Classes/ShareKit/Sharers/Services/Facebook/**/*.{h,m}'
facebook.compiler_flags = '-Wno-incomplete-implementation -Wno-missing-prototypes'
facebook.dependency 'Facebook-iOS-SDK'
end
# ...
end
```
13 changes: 8 additions & 5 deletions iOSNote/CocoaPods/cocoapods-plugins.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
## cocoapods plugins


> sudo gem update --system
> podfile : plugin 'plugin name'
> User:【podfile : plugin 'plugin name'
> install:`$ sudo gem plugin name`
Expand All @@ -14,16 +13,18 @@

### [cocoapods-binary ](https://github.com/leavez/cocoapods-binary/)

> 构建二进制适合本地Debug使用
- remote pod transfer to framework

- sudo gem install cocoapods-binary

### [cocoapods-pod-merge](https://github.com/grab/cocoapods-pod-merge)

- group 业务拆分组合划分层
> group Pod组件合并插件
<details>
<summary> 点击展开 </summary>
<summary> 点击展开示例说明 </summary>

> pod install 源码OK,二进制需要对应remote自身再桥接。
Expand Down Expand Up @@ -55,7 +56,7 @@ end

### [pod-dependencies](https://github.com/segiddins/cocoapods-dependencies)

> dependencies
> dependencies:分析当前组件依赖细节
- sudo gem install cocoapods-dependencies

Expand All @@ -68,6 +69,8 @@ end

> 只适用于远端库(本质从远端clone再处理)
> M1并无适配及产物架构不可自定义,不建议使用!
- sudo gem install cocoapods-packager

- your Gemfile:gem "cocoapods-packager" && bundle install
Expand Down
Loading

0 comments on commit 7ff3b21

Please sign in to comment.