From c0bc29486f72906d450f1867f76be9009df1536e Mon Sep 17 00:00:00 2001 From: edwinQQQ Date: Mon, 11 Aug 2025 14:51:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=BF=9E=E5=87=BB=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=8C=85?= =?UTF-8?q?=E5=90=AB=E5=BC=BA=E5=88=B6=E9=87=8D=E7=BD=AE=E8=BF=9E=E5=87=BB?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E7=9A=84=E6=96=B9=E6=B3=95=E5=92=8C=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E7=94=9F=E5=91=BD=E5=91=A8=E6=9C=9F=E4=BF=9D=E6=8A=A4?= =?UTF-8?q?=EF=BC=9B=E5=9C=A8=20XPSendGiftView=20=E5=92=8C=20GiftComboMana?= =?UTF-8?q?ger=20=E4=B8=AD=E5=AE=9E=E7=8E=B0=E7=9B=B8=E5=85=B3=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=8C=E7=A1=AE=E4=BF=9D=20UI=20=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E4=B8=8E=E8=BF=9E=E5=87=BB=E7=8A=B6=E6=80=81=E4=B8=80=E8=87=B4?= =?UTF-8?q?=EF=BC=9B=E6=B3=A8=E5=86=8C=E9=80=9A=E7=9F=A5=E4=BB=A5=E5=A4=84?= =?UTF-8?q?=E7=90=86=E8=BF=9E=E5=87=BB=E7=8A=B6=E6=80=81=E7=9A=84=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E9=87=8D=E7=BD=AE=EF=BC=8C=E5=A2=9E=E5=BC=BA=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E4=BD=93=E9=AA=8C=E5=92=8C=E7=B3=BB=E7=BB=9F=E7=A8=B3?= =?UTF-8?q?=E5=AE=9A=E6=80=A7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YuMi/Modules/YMMessage/Tool/NIMSDKManager.h | 2 + YuMi/Modules/YMMessage/Tool/NIMSDKManager.m | 2 + .../View/SendGiftView/GiftComboManager.h | 4 ++ .../View/SendGiftView/GiftComboManager.m | 63 ++++++++++++++++++- .../View/SendGiftView/View/XPSendGiftView.h | 6 ++ .../View/SendGiftView/View/XPSendGiftView.m | 62 ++++++++++++++++++ .../YMRoom/View/XPRoomViewController.m | 53 ++++++++++++++++ docs/AttachmentModel_Analysis_Report.md | 2 + docs/NIMSDKManager_Usage_Guide.md | 2 + docs/NIMSDK_Integration_Documentation.md | 2 + 10 files changed, 195 insertions(+), 3 deletions(-) diff --git a/YuMi/Modules/YMMessage/Tool/NIMSDKManager.h b/YuMi/Modules/YMMessage/Tool/NIMSDKManager.h index 7e60c434..24d4b323 100644 --- a/YuMi/Modules/YMMessage/Tool/NIMSDKManager.h +++ b/YuMi/Modules/YMMessage/Tool/NIMSDKManager.h @@ -258,3 +258,5 @@ typedef void(^NIMSDKStatusChangeBlock)(NIMSDKLoginStatus status); NS_ASSUME_NONNULL_END + + diff --git a/YuMi/Modules/YMMessage/Tool/NIMSDKManager.m b/YuMi/Modules/YMMessage/Tool/NIMSDKManager.m index 7ee8b585..1d37d398 100644 --- a/YuMi/Modules/YMMessage/Tool/NIMSDKManager.m +++ b/YuMi/Modules/YMMessage/Tool/NIMSDKManager.m @@ -404,3 +404,5 @@ @end + + diff --git a/YuMi/Modules/YMRoom/View/SendGiftView/GiftComboManager.h b/YuMi/Modules/YMRoom/View/SendGiftView/GiftComboManager.h index c4922412..293e6d9d 100644 --- a/YuMi/Modules/YMRoom/View/SendGiftView/GiftComboManager.h +++ b/YuMi/Modules/YMRoom/View/SendGiftView/GiftComboManager.h @@ -28,6 +28,9 @@ typedef enum : NSUInteger { } ComboFlagActionType; +// 通知常量定义 +UIKIT_EXTERN NSString * const kBoomStateForceResetNotification; + NS_ASSUME_NONNULL_BEGIN @interface GiftComboManager : NSObject @@ -58,6 +61,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)resetCombo; - (void)sendGift; - (void)forceRemove; +- (void)forceBoomStateReset; - (BOOL)loadEnable; // 第一个 combo 由 send gift view 发起,需要手动 combo + 1 diff --git a/YuMi/Modules/YMRoom/View/SendGiftView/GiftComboManager.m b/YuMi/Modules/YMRoom/View/SendGiftView/GiftComboManager.m index ffc07559..d5255e0f 100644 --- a/YuMi/Modules/YMRoom/View/SendGiftView/GiftComboManager.m +++ b/YuMi/Modules/YMRoom/View/SendGiftView/GiftComboManager.m @@ -8,6 +8,8 @@ #import "GiftComboManager.h" +#import +#import #import #import "Api+Gift.h" @@ -20,6 +22,9 @@ #import "GiftComboFlagView.h" +// 通知常量实现 +NSString * const kBoomStateForceResetNotification = @"BoomStateForceResetNotification"; + @interface GiftComboManager () @property (nonatomic, assign) BOOL enableCombo; @@ -126,13 +131,65 @@ } - (void)forceRemove { + // 调用新的强制重置方法 + [self forceBoomStateReset]; + + // 通知UI移除连击面板 if (self.actionCallback) { self.actionCallback(ComboAction_RemovePanel); } - if (self.handleRoomUIChanged) { - self.handleRoomUIChanged(NO); - } +} + +- (void)forceBoomStateReset { + NSLog(@"🚨 执行强制Boom连击状态重置"); + + // 1. 立即停止所有定时器(无条件停止) + [self forceStopAllTimers]; + + // 2. 清空所有队列 + [self clearAllQueues]; + + // 3. 重置所有状态标志 self.isCombing = NO; + self.enableCombo = NO; + + // 4. 清理回调 + self.actionCallback = nil; + + // 5. 发送通知(优先级最高,通知所有相关组件) + dispatch_async(dispatch_get_main_queue(), ^{ + [[NSNotificationCenter defaultCenter] postNotificationName:kBoomStateForceResetNotification + object:nil]; + }); + + // 6. 强制恢复UI(确保底部栏和侧栏显示) + if (self.handleRoomUIChanged) { + dispatch_async(dispatch_get_main_queue(), ^{ + self.handleRoomUIChanged(NO); + }); + } +} + +// 无条件停止定时器 +- (void)forceStopAllTimers { + if (self.timer) { + dispatch_source_cancel(self.timer); + self.timer = nil; // 立即置空,不等待回调 + } + + if (self.comboFlagTimer) { + dispatch_source_cancel(self.comboFlagTimer); + self.comboFlagTimer = nil; + } +} + +// 清空所有队列 +- (void)clearAllQueues { + @synchronized (self) { + [self.requestQueue removeAllObjects]; + [self.giftComboQueue removeAllObjects]; + [self.comboFlagQueue removeAllObjects]; + } } - (NSInteger)loadComboCountFromSendGiftView { diff --git a/YuMi/Modules/YMRoom/View/SendGiftView/View/XPSendGiftView.h b/YuMi/Modules/YMRoom/View/SendGiftView/View/XPSendGiftView.h index 6d15bfba..8379a3d8 100644 --- a/YuMi/Modules/YMRoom/View/SendGiftView/View/XPSendGiftView.h +++ b/YuMi/Modules/YMRoom/View/SendGiftView/View/XPSendGiftView.h @@ -36,6 +36,12 @@ typedef NS_ENUM(NSInteger, SendGiftType) { ///选中的礼物id @property (nonatomic, copy) NSString *selectGiftId; +// 移除连击相关视图 +- (void)removeAllComboRelatedViews; + +// 强制重置连击状态 +- (void)forceBoomStateReset; + @end NS_ASSUME_NONNULL_END diff --git a/YuMi/Modules/YMRoom/View/SendGiftView/View/XPSendGiftView.m b/YuMi/Modules/YMRoom/View/SendGiftView/View/XPSendGiftView.m index eea45ea3..c2baada1 100644 --- a/YuMi/Modules/YMRoom/View/SendGiftView/View/XPSendGiftView.m +++ b/YuMi/Modules/YMRoom/View/SendGiftView/View/XPSendGiftView.m @@ -128,6 +128,62 @@ UIKIT_EXTERN NSString * const kFreeGiftCountdownNotification; } } +#pragma mark - 连击状态管理 + +// 移除连击相关视图 +- (void)removeAllComboRelatedViews { + // 移除连击面板 + if (self.comboView && self.comboView.superview) { + [self.comboView stopTimer]; + [self.comboView endCombo]; + [self.comboView removeFromSuperview]; + self.comboView = nil; + } + + // 恢复其他视图的显示状态 + self.contentView.hidden = NO; + if (self->_constellationBanner) { + self.constellationBanner.hidden = NO; + } + if (self->_luckyBroadcastView) { + self.luckyBroadcastView.hidden = NO; + } + if (self->_bravoGiftView) { + self.bravoGiftView.hidden = NO; + } +} + +// 强制重置连击状态 +- (void)forceBoomStateReset { + NSLog(@"🔧 XPSendGiftView 强制重置连击状态"); + + // 1. 移除连击相关视图 + [self removeAllComboRelatedViews]; + + // 2. 重置连击管理器状态 + [[GiftComboManager sharedManager] forceBoomStateReset]; +} + +// 处理连击状态强制重置通知 +- (void)handleBoomStateForceReset:(NSNotification *)notification { + NSLog(@"📢 XPSendGiftView 收到连击状态强制重置通知"); + + // 只处理视图相关的重置,不再调用 GiftComboManager 的重置 + // 因为通知是由 GiftComboManager 发出的,避免循环调用 + [self removeAllComboRelatedViews]; +} + +// 视图控制器生命周期保护 +- (void)viewWillDisappear:(BOOL)animated { + [super viewWillDisappear:animated]; + + // 如果连击正在进行,强制重置 + if ([[GiftComboManager sharedManager] isGiftCombing]) { + NSLog(@"📱 礼物面板即将消失,检查连击状态"); + [self forceBoomStateReset]; + } +} + - (instancetype)initWithType:(SendGiftType)type uid:(NSString * __nullable)uid{ if (self = [super init]) { self.modalPresentationStyle = UIModalPresentationOverFullScreen; @@ -140,6 +196,12 @@ UIKIT_EXTERN NSString * const kFreeGiftCountdownNotification; - (void)viewDidLoad { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getFreeGiftCountdownNotification:) name:kFreeGiftCountdownNotification object:nil]; + + // 注册连击状态强制重置通知 + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(handleBoomStateForceReset:) + name:kBoomStateForceResetNotification + object:nil]; [self initSubViews]; [self initSubViewConstraints]; diff --git a/YuMi/Modules/YMRoom/View/XPRoomViewController.m b/YuMi/Modules/YMRoom/View/XPRoomViewController.m index 037bf7c3..513af5ae 100644 --- a/YuMi/Modules/YMRoom/View/XPRoomViewController.m +++ b/YuMi/Modules/YMRoom/View/XPRoomViewController.m @@ -364,6 +364,12 @@ XPCandyTreeInsufficientBalanceViewDelegate> dispatch_async(dispatch_get_main_queue(), ^{ self.sideMenu.hidden = comboViewDisplay; self.menuContainerView.hidden = comboViewDisplay; + + // 添加状态验证:如果要隐藏UI,确保连击确实在进行 + if (comboViewDisplay && ![[GiftComboManager sharedManager] isGiftCombing]) { + NSLog(@"⚠️ 检测到UI隐藏请求但连击未进行,执行强制重置"); + [self forceBoomStateReset]; + } }); }]; } @@ -415,6 +421,12 @@ XPCandyTreeInsufficientBalanceViewDelegate> - (void)setupNotifications { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myGiftEffectUpdate:) name:kRoomGiftEffectUpdateNotificationKey object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(openRedPacketNotification:) name:@"kOpenRedPacketNotification" object:nil]; + + // 添加应用生命周期保护 + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(applicationDidEnterBackground:) + name:UIApplicationDidEnterBackgroundNotification + object:nil]; @kWeakify(self); [[NSNotificationCenter defaultCenter] addObserverForName:@"kExchangeRoomAnimationViewAndGameViewIndex" @@ -497,6 +509,12 @@ XPCandyTreeInsufficientBalanceViewDelegate> -(void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated]; self.freeView.hidden = YES; + + // 如果连击正在进行,强制重置 + if ([[GiftComboManager sharedManager] isGiftCombing]) { + NSLog(@"📱 房间即将退出,检查连击状态"); + [self forceBoomStateReset]; + } } - (void)viewDidDisappear:(BOOL)animated{ @@ -511,6 +529,41 @@ XPCandyTreeInsufficientBalanceViewDelegate> [XPSkillCardPlayerManager shareInstance].isInRoomVC = YES; } +#pragma mark - 连击状态管理 + +// 强制重置连击状态和恢复UI +- (void)forceBoomStateReset { + NSLog(@"🔧 XPRoomViewController 强制重置连击状态"); + + // 1. 直接重置连击管理器(会自动发送通知给所有相关组件) + [[GiftComboManager sharedManager] forceBoomStateReset]; + + // 2. 确保UI恢复(双重保障) + dispatch_async(dispatch_get_main_queue(), ^{ + self.sideMenu.hidden = NO; + self.menuContainerView.hidden = NO; + NSLog(@"🔄 强制恢复底部操作栏和侧栏显示"); + }); +} + +// 应用生命周期保护 +- (void)applicationDidEnterBackground:(NSNotification *)notification { + if ([[GiftComboManager sharedManager] isGiftCombing]) { + NSLog(@"📱 应用进入后台,检查连击状态"); + [self forceBoomStateReset]; + } +} + +// 内存警告保护 +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + + if ([[GiftComboManager sharedManager] isGiftCombing]) { + NSLog(@"⚠️ 收到内存警告,检查连击状态"); + [self forceBoomStateReset]; + } +} + #pragma mark - Private Method - (void)initSubViews { self.view.backgroundColor = [UIColor darkGrayColor]; diff --git a/docs/AttachmentModel_Analysis_Report.md b/docs/AttachmentModel_Analysis_Report.md index 44da65fe..123e05f9 100644 --- a/docs/AttachmentModel_Analysis_Report.md +++ b/docs/AttachmentModel_Analysis_Report.md @@ -420,3 +420,5 @@ if (![partitionId isEqualToString:self.userInfo.partitionId]) { **最后更新**: 2024年12月 **维护人员**: 开发团队 + + diff --git a/docs/NIMSDKManager_Usage_Guide.md b/docs/NIMSDKManager_Usage_Guide.md index c3a8f119..a40e48b2 100644 --- a/docs/NIMSDKManager_Usage_Guide.md +++ b/docs/NIMSDKManager_Usage_Guide.md @@ -616,3 +616,5 @@ A: 检查APNS证书配置,确保设备Token正确上传。 **最后更新**: 2024年12月 **维护人员**: 开发团队 + + diff --git a/docs/NIMSDK_Integration_Documentation.md b/docs/NIMSDK_Integration_Documentation.md index eeeedacf..9a19f792 100644 --- a/docs/NIMSDK_Integration_Documentation.md +++ b/docs/NIMSDK_Integration_Documentation.md @@ -553,3 +553,5 @@ A: 检查推送消息格式,确保解析逻辑正确。 **最后更新**: 2024年12月 **维护人员**: 开发团队 + +