build-ipa/ironSource/PlayBTopOn/DEBUG_CRASH_GUIDE.md
2026-01-05 10:40:05 +08:00

187 lines
5.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 调试崩溃问题指南
## 问题现象
`NSLog("XS- init config")` 这个日志都没有打印出来,说明应用在调用 `BbbAdManager.shared.initConfig()` 之前就崩溃了。
## 已添加的调试日志
### 1. AppDelegate.swift
```swift
NSLog("XS- app start 21") // 第 26 行
NSLog("XS- 准备访问 BbbAdManager.shared") // 新增
NSLog("XS- BbbAdManager.shared 访问成功") // 新增
NSLog("XS- 准备调用 initConfig()") // 新增
adManager.initConfig()
NSLog("XS- app start 3") // 原有
```
### 2. bbbAdManager.swift - bConfig 初始化
```swift
NSLog("XS- bConfig init 开始")
NSLog("XS- bConfig init: allAdIds count = ...")
NSLog("XS- bConfig init 完成")
```
### 3. bbbAdManager.swift - BbbAdManager 初始化
```swift
NSLog("XS- 开始创建 BbbAdManager.config")
NSLog("XS- BbbAdManager.config 创建完成")
NSLog("XS- 开始创建 BbbAdManager.shared 单例")
NSLog("XS- BbbAdManager init 开始")
NSLog("XS- BbbAdManager init 完成")
NSLog("XS- BbbAdManager.shared 单例创建完成")
```
### 4. bbbAdManager.swift - initConfig
```swift
NSLog("XS- init config") // 第一行
NSLog("XS- init config 1")
NSLog("XS- init config 2")
NSLog("XS- init config 3")
```
### 5. YL_PlayVC.swift
```swift
NSLog("XS- YL_PlayVC viewDidLoad 开始")
NSLog("XS- YL_PlayVC 准备调用 waitForSDKInitialization")
NSLog("XS- YL_PlayVC waitForSDKInitialization 调用完成")
```
## 下一步操作
### 步骤 1: 更新 CocoaPods 依赖
我已经更新了 `Podfile`,将最低版本设置为 iOS 12.0
```bash
cd /Users/mac/workspaces/projects/ios/build-ipa/ironSource/PlayBTopOn
pod install
```
### 步骤 2: 在 Xcode 中配置弱链接
**重要!这一步必须做,否则还是会崩溃:**
1. 打开 `PlayBTopOn.xcworkspace`
2. 选择项目 → TARGETS → PlayBTopOn
3. Build Phases → Link Binary With Libraries
4.`AppTrackingTransparency.framework` 的 Status 改为 **Optional**
### 步骤 3: 清理并重新编译
```bash
# 在 Xcode 中:
# 1. Product -> Clean Build Folder (Cmd+Shift+K)
# 2. Product -> Build (Cmd+B)
# 3. Product -> Run (Cmd+R)
```
### 步骤 4: 查看控制台日志
运行应用后,查看 Xcode 控制台的输出,找到最后打印的日志,就能确定崩溃发生在哪一步。
## 可能的崩溃原因
根据日志输出,可以判断崩溃原因:
### 场景 1: 看不到 "XS- 开始创建 BbbAdManager.config"
**原因:** 导入 `AnyThinkSDK``AnyThinkInterstitial` 时崩溃
**解决:** 这些 SDK 可能不支持 iOS 12/13需要检查 SDK 文档或升级版本
### 场景 2: 看到 "XS- 开始创建 BbbAdManager.config" 但没有 "完成"
**原因:** `bConfig()` 初始化时崩溃
**解决:** 检查 `bConfig``init()` 方法中的代码
### 场景 3: 看到 "XS- BbbAdManager.config 创建完成" 但没有 "开始创建 shared"
**原因:** 在创建 `shared` 单例之前的某个地方崩溃
**解决:** 检查类级别的其他静态变量
### 场景 4: 看到 "XS- 开始创建 BbbAdManager.shared" 但没有 "init 完成"
**原因:** `BbbAdManager``init()` 方法中崩溃
**解决:** 检查 init 方法的代码
### 场景 5: 看到 "XS- 准备访问 BbbAdManager.shared" 但没有 "访问成功"
**原因:** 访问 `BbbAdManager.shared` 时触发初始化崩溃
**解决:** 检查静态变量的初始化顺序
### 场景 6: 看到 "XS- 准备调用 initConfig()" 但没有 "XS- init config"
**原因:** 调用 `initConfig()` 方法时崩溃
**解决:** 检查方法调用本身是否有问题
## 最可能的原因
根据经验,最可能的原因是:
### 1. 广告 SDK 不支持 iOS 12/13
TopOn (AnyThink) SDK 6.4.93 版本可能需要 iOS 13+ 或更高。
**验证方法:**
查看 Pods 目录下的 SDK 文档或 Info.plist
```bash
cat Pods/TPNiOS/core/AnyThinkSDK.xcframework/Info.plist | grep MinimumOSVersion
```
**解决方案:**
- 如果 SDK 不支持 iOS 12需要降级到支持的版本
- 或者将最低支持版本改为 iOS 13
### 2. AppTrackingTransparency 框架未设置为 Optional
这个必须在 Xcode 中手动设置(见上面步骤 2
### 3. 某些广告 SDK 框架也需要弱链接
某些广告平台的 SDK 可能也包含 iOS 14+ 的 API需要设置为 Optional
## 如何查看详细的崩溃信息
### 方法 1: Xcode 控制台
直接在 Xcode 底部的控制台查看崩溃信息
### 方法 2: 设置异常断点
1. Xcode → Breakpoint Navigator (⌘7)
2. 点击左下角 `+` → Exception Breakpoint
3. 运行应用,崩溃时会自动在崩溃处暂停
### 方法 3: 查看设备日志
1. Xcode → Window → Devices and Simulators
2. 选择你的设备
3. 点击 "Open Console" 查看系统日志
## 临时解决方案:提高最低版本
如果广告 SDK 确实不支持 iOS 12可以临时将最低版本改为 iOS 13
### Podfile
```ruby
platform :ios, '13.0'
```
### project.pbxproj (在 Xcode 中设置)
1. 项目设置 → General → Deployment Info
2. iOS Deployment Target 设置为 13.0
## 需要反馈的信息
请运行应用后,把控制台的输出(特别是所有 "XS-" 开头的日志)发给我,我可以帮你精确定位问题。
示例输出:
```
XS- app start: xxx
XS- app start 2: xxx
XS- YL_PlayVC viewDidLoad 开始
XS- app start 21: xxx
XS- 准备访问 BbbAdManager.shared
XS- 开始创建 BbbAdManager.config
XS- bConfig init 开始
XS- bConfig init: allAdIds count = 3
[崩溃] <--- 如果在这里崩溃,就说明问题出在 bConfig 的 init 方法中
```
---
**总结:**
1. ✅ 已添加详细日志
2. ✅ 已更新 Podfile
3. ⚠️ 需要运行 `pod install`
4. ⚠️ 需要在 Xcode 中设置 AppTrackingTransparency 为 Optional
5. ⚠️ 重新编译运行,查看日志确定崩溃点