新增连击状态管理功能,包含强制重置连击状态的方法和应用生命周期保护;在 XPSendGiftView 和 GiftComboManager 中实现相关逻辑,确保 UI 状态与连击状态一致;注册通知以处理连击状态的强制重置,增强用户体验和系统稳定性。

This commit is contained in:
edwinQQQ
2025-08-11 14:51:57 +08:00
parent 1fb6cadabf
commit c0bc29486f
10 changed files with 195 additions and 3 deletions

View File

@@ -258,3 +258,5 @@ typedef void(^NIMSDKStatusChangeBlock)(NIMSDKLoginStatus status);
NS_ASSUME_NONNULL_END

View File

@@ -404,3 +404,5 @@
@end

View File

@@ -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

View File

@@ -8,6 +8,8 @@
#import "GiftComboManager.h"
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <Bugly/Bugly.h>
#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 {

View File

@@ -36,6 +36,12 @@ typedef NS_ENUM(NSInteger, SendGiftType) {
///选中的礼物id
@property (nonatomic, copy) NSString *selectGiftId;
// 移除连击相关视图
- (void)removeAllComboRelatedViews;
// 强制重置连击状态
- (void)forceBoomStateReset;
@end
NS_ASSUME_NONNULL_END

View File

@@ -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];

View File

@@ -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];

View File

@@ -420,3 +420,5 @@ if (![partitionId isEqualToString:self.userInfo.partitionId]) {
**最后更新**: 2024年12月
**维护人员**: 开发团队

View File

@@ -616,3 +616,5 @@ A: 检查APNS证书配置确保设备Token正确上传。
**最后更新**: 2024年12月
**维护人员**: 开发团队

View File

@@ -553,3 +553,5 @@ A: 检查推送消息格式,确保解析逻辑正确。
**最后更新**: 2024年12月
**维护人员**: 开发团队