Files
real-e-party-iOS/YuMi/Global/BuglyManager_README.md
edwinQQQ a35a711be6 chore: Initial clean commit
- Removed YuMi/Library/ (138 MB, not tracked)
- Removed YuMi/Resources/ (23 MB, not tracked)
- Removed old version assets (566 files, not tracked)
- Excluded Pods/, xcuserdata/ and other build artifacts
- Clean repository optimized for company server deployment
2025-10-09 16:19:14 +08:00

130 lines
3.3 KiB
Markdown

# BuglyManager 使用说明
## 概述
`BuglyManager` 是一个统一的 Bugly 管理类,封装了所有 Bugly 相关操作,提供统一的错误上报和性能监控接口。
## 主要功能
### 1. 统一错误上报
- 业务错误上报
- 网络错误上报
- 内购错误上报
- 自定义错误上报
### 2. 卡顿监听
- 自动检测主线程卡顿
- 支持代理回调通知
- 可配置卡顿阈值
### 3. 性能监控
- 主线程阻塞检测
- 异常退出检测
- 自定义日志级别
## 使用方法
### 1. 初始化配置
```objc
// 在 AppDelegate 中配置
#ifdef DEBUG
[[BuglyManager sharedManager] configureWithAppId:@"c937fd00f7" debug:YES];
#else
[[BuglyManager sharedManager] configureWithAppId:@"8627948559" debug:NO];
#endif
```
### 2. 设置代理监听卡顿
```objc
// 在需要监听卡顿的类中
@interface YourClass : NSObject <BuglyManagerDelegate>
@end
@implementation YourClass
- (void)setupBuglyDelegate {
[BuglyManager sharedManager].delegate = self;
}
- (void)buglyManager:(BuglyManager *)manager didDetectLag:(NSTimeInterval)duration {
NSLog(@"检测到卡顿,持续时间: %.2f 秒", duration);
// TODO: 实现卡顿通知逻辑
}
@end
```
### 3. 错误上报
#### 业务错误上报
```objc
NSDictionary *context = @{
@"page": @"HomePage",
@"action": @"loadData"
};
[[BuglyManager sharedManager] reportBusinessError:@"数据加载失败"
code:1001
context:context];
```
#### 网络错误上报
```objc
NSDictionary *userInfo = @{
@"requestParams": @{@"userId": @"12345"},
@"responseData": @"服务器错误"
};
[[BuglyManager sharedManager] reportNetworkError:@"user123"
api:@"user/profile"
code:500
userInfo:userInfo];
```
#### 内购错误上报
```objc
NSDictionary *context = @{
@"retryCount": @3,
@"productId": @"com.yumi.coin100"
};
[[BuglyManager sharedManager] reportIAPError:@"user123"
transactionId:@"txn_123456"
orderId:@"order_789"
status:2
context:context];
```
## 重构完成情况
### ✅ 已完成
1. 创建 `BuglyManager.h``BuglyManager.m`
2. 修改 `AppDelegate+ThirdConfig.m` 使用 BuglyManager
3. 修改 `IAPManager.m` 使用 BuglyManager
4. 修改 `HttpRequestHelper.m` 使用 BuglyManager
5. 修改 `GiftComboManager.m` 使用 BuglyManager
6. 创建使用示例和文档
### 🔄 进行中
1. 修改 `XPGiftPresenter.m` 使用 BuglyManager
### 📋 待完成
1. 测试验证所有功能
2. 完善卡顿通知逻辑
3. 性能优化
## 优势
1. **统一管理**:所有 Bugly 相关操作集中在一个类中
2. **降低耦合**:其他模块无需直接引入 Bugly 头文件
3. **易于维护**:统一的接口和错误处理逻辑
4. **功能扩展**:支持卡顿监听和自定义通知
5. **向后兼容**:保持现有功能完全不变
## 注意事项
1. 确保在真机环境下编译,模拟器可能无法正确导入 Bugly 头文件
2. 卡顿监听功能需要在实际设备上测试
3. 错误上报是异步操作,不会阻塞主线程
4. 建议在 AppDelegate 中尽早初始化 BuglyManager