新增 QEmotionBoardView 表情不显示问题分析报告和排查报告,详细记录问题描述、代码逻辑、根因分析及解决方案。同时,修复 AppDelegate 中的图片加载逻辑,添加调试日志以便于后续排查,确保表情正常显示。

This commit is contained in:
edwinQQQ
2025-08-26 13:57:24 +08:00
parent c5cde5b5c4
commit 77fd8b51c2
9 changed files with 451 additions and 27 deletions

View File

@@ -161,22 +161,31 @@ UIKIT_EXTERN NSString * adImageName;
NSMutableArray * array = [NSMutableArray array];
for (int i = 0; i < emojiArray.count; i++) {
UIImage * image = [UIImage imageNamed:dic[@"file"]];
NSDictionary * emotionDic = [emojiArray xpSafeObjectAtIndex:i];
if (!emotionDic) continue;
UIImage * image = [UIImage imageNamed:emotionDic[@"file"]];
QEmotion * info = [[QEmotion alloc] init];
NSDictionary * dic = [emojiArray xpSafeObjectAtIndex:i];
if (dic) {
info.displayName = dic[@"tag"];
info.identifier = dic[@"id"];
}
info.displayName = emotionDic[@"tag"];
info.identifier = emotionDic[@"id"];
info.image = image;
//
NSLog(@"加载表情: %@, 图片: %@, 是否成功: %@", info.displayName, emotionDic[@"file"], image ? @"是" : @"否");
[array addObject:info];
}
//
QEmotionHelper *faceManager = [QEmotionHelper sharedEmotionHelper];
faceManager.emotionArray = array;
//
NSLog(@"表情数组加载完成,总数: %lu", (unsigned long)array.count);
for (int i = 0; i < MIN(array.count, 3); i++) {
QEmotion *emotion = array[i];
NSLog(@"测试表情 %d: %@, 图片: %@", i, emotion.displayName, emotion.image ? @"加载成功" : @"加载失败");
}
});
}

View File

@@ -128,3 +128,4 @@
<Emoticon ID="emoticon_emoji_115" Tag="[自行车]" File="emoji_115.png" />
</Catalog>
</PopoEmoticons>
˜

View File

@@ -111,6 +111,10 @@ const int UISendButtonHeight = 41;
if (isSizeChanged) {
[self setNeedsLayoutEmotions];
}
//
NSLog(@"UIEmotionPageView layoutSubviews: frame=%@, needsLayoutEmotions=%d", NSStringFromCGRect(self.frame), self.needsLayoutEmotions);
[self layoutEmotionsIfNeeded];
}
@@ -120,6 +124,14 @@ const int UISendButtonHeight = 41;
- (void)setEmotions:(NSArray<QEmotion *> *)emotions {
if ([_emotions isEqualToArray:emotions]) return;
//
NSLog(@"UIEmotionPageView setEmotions: 表情数量=%lu", (unsigned long)emotions.count);
if (emotions.count > 0) {
QEmotion *firstEmotion = emotions[0];
NSLog(@"UIEmotionPageView 第一个表情: %@, 图片: %@", firstEmotion.displayName, firstEmotion.image ? @"存在" : @"不存在");
}
_emotions = emotions;
[self setNeedsLayoutEmotions];
[self setNeedsLayout];
@@ -156,6 +168,13 @@ const int UISendButtonHeight = 41;
}
emotionlayer.contents = (__bridge id)(self.emotions[i].image.CGImage);//使layer
//
if (i < 3) { // 3
NSLog(@"渲染表情 %ld: %@, 图片: %@, CGImage: %@", (long)i, self.emotions[i].displayName,
self.emotions[i].image ? @"存在" : @"不存在",
self.emotions[i].image.CGImage ? @"存在" : @"不存在");
}
NSInteger row = i / emotionCountPerRow;
emotionOrigin.x = self.padding.left + (self.emotionSize.width + emotionHorizontalSpacing) * (i % emotionCountPerRow);
emotionOrigin.y = self.padding.top + (self.emotionSize.height + emotionVerticalSpacing) * row;
@@ -246,12 +265,29 @@ const int UISendButtonHeight = 41;
emotionVerticalSpacing:(CGFloat)emotionVerticalSpacing
emotionSelectedBackgroundExtension:(UIEdgeInsets)emotionSelectedBackgroundExtension
paddingInPage:(UIEdgeInsets)paddingInPage {
//
NSLog(@"UIEmotionVerticalScrollView setEmotions: 表情数量=%lu, emotionSize=%@", (unsigned long)emotions.count, NSStringFromCGSize(emotionSize));
if (emotions.count > 0) {
QEmotion *firstEmotion = emotions[0];
NSLog(@"第一个表情: %@, 图片: %@", firstEmotion.displayName, firstEmotion.image ? @"存在" : @"不存在");
}
UIEmotionPageView *pageView = self.pageView;
pageView.emotions = emotions;
pageView.padding = paddingInPage;
//
NSLog(@"UIEmotionVerticalScrollView bounds: %@", NSStringFromCGRect(self.bounds));
NSLog(@"UIEmotionVerticalScrollView paddingInPage: %@", NSStringFromUIEdgeInsets(paddingInPage));
CGSize contentSize = CGSizeMake(self.bounds.size.width - [self edgeInsetsGetHorizontalValue:paddingInPage], self.bounds.size.height - [self edgeInsetsGetVerticalValue:paddingInPage]);
NSLog(@"UIEmotionVerticalScrollView contentSize: %@", NSStringFromCGSize(contentSize));
NSInteger emotionCountPerRow = (contentSize.width + minimumEmotionHorizontalSpacing) / (emotionSize.width + minimumEmotionHorizontalSpacing);
pageView.numberOfRows = ceil(emotions.count / (CGFloat)emotionCountPerRow);
NSLog(@"UIEmotionVerticalScrollView emotionCountPerRow: %ld, numberOfRows: %ld", (long)emotionCountPerRow, (long)pageView.numberOfRows);
pageView.emotionSize =emotionSize;
pageView.emotionSelectedBackgroundExtension = emotionSelectedBackgroundExtension;
pageView.minimumEmotionHorizontalSpacing = minimumEmotionHorizontalSpacing;
@@ -370,6 +406,14 @@ const int UISendButtonHeight = 41;
- (void)setEmotions:(NSArray<QEmotion *> *)emotions {
_emotions = emotions;
//
NSLog(@"QEmotionBoardView 设置表情数组,数量: %lu", (unsigned long)emotions.count);
for (int i = 0; i < MIN(emotions.count, 5); i++) {
QEmotion *emotion = emotions[i];
NSLog(@"表情 %d: %@, 图片: %@", i, emotion.displayName, emotion.image ? @"存在" : @"不存在");
}
[self setNeedsLayout];
}

View File

@@ -808,6 +808,8 @@ typedef NS_ENUM(NSUInteger, CustomMessageTypeRoomLevelUpdate) {
@property(nonatomic, assign) NSInteger seq; // 本地序号,用于将一条消息分解为多条有次序的消息
@property (nonatomic, assign) BOOL isFromPublic;
@end
NS_ASSUME_NONNULL_END

View File

@@ -23,6 +23,8 @@
@property (nonatomic, copy) NSString *currentUserId;
@property (nonatomic, strong) UserInfoModel *userInfo;
@end
@implementation PublicRoomManager
@@ -217,6 +219,7 @@
NSMutableDictionary *ext = [NSMutableDictionary dictionaryWithObject:extModel.model2dictionary
forKey:[NSString stringWithFormat:@"%ld", self.userInfo.uid]];
request.roomExt = [ext toJSONString];
request.retryCount = 3;
//
@kWeakify(self);
@@ -373,6 +376,10 @@
- (void)onRecvMessages:(NSArray<NIMMessage *> *)messages {
//
for (NIMMessage *message in messages) {
if ([message.session.sessionId isEqualToString:self.currentPublicRoomId]) {
[self handleMessageWithAttachmentAndFirstSecond:message];
}
/*
if (message.session.sessionType == NIMSessionTypeChatroom) {
NSString *sessionId = message.session.sessionId;
if ([sessionId isEqualToString:self.currentPublicRoomId]) {
@@ -382,6 +389,7 @@
NIMCustomObject *obj = (NIMCustomObject *) message.messageObject;
attachment = (AttachmentModel *) obj.attachment;
if (attachment.first > 0 && attachment.second >0) {
attachment.isFromPublic = YES;
[self handleMessageWithAttachmentAndFirstSecond:message];
}
// if (attachment) {
@@ -402,11 +410,18 @@
// messageExt.roomExt);
}
}
*/
}
}
- (void)handleMessageWithAttachmentAndFirstSecond:(NIMMessage *)message {
//
if (![XPSkillCardPlayerManager shareInstance].isInRoom) {
NSLog(@"PublicRoomManager: 用户未在房间中,跳过消息转发");
return;
}
[[NSNotificationCenter defaultCenter] postNotificationName:@"MessageFromPublicRoomWithAttachmentNotification"
object:message];
}
- (void)handleFirst_106:(AttachmentModel *)attachment

View File

@@ -9,7 +9,7 @@
#import "XPMessageRemoteExtModel.h"
// 公共房间消息转发通知名称
UIKIT_EXTERN NSString * const kMessageFromPublicRoomWithAttachmentNotification;
UIKIT_EXTERN NSString * _Nullable const kMessageFromPublicRoomWithAttachmentNotification;
NS_ASSUME_NONNULL_BEGIN

View File

@@ -1932,9 +1932,21 @@ XPCandyTreeInsufficientBalanceViewDelegate>
}
if (![message.session.sessionId isEqualToString:@(self.roomInfo.roomId).stringValue]) {
NSLog(@"[Recv] ⛔️ 过滤:房间不匹配 | msg.sid=%@ | curRoomId=%@",
message.session.sessionId, @(self.roomInfo.roomId).stringValue);
continue;
// if (message.messageType == NIMMessageTypeCustom) {
// NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
// if ([obj.attachment isKindOfClass:[AttachmentModel class]]) {
// AttachmentModel *att = (AttachmentModel *)obj.attachment;
// if (!att.isFromPublic) {
// NSLog(@"[Recv] ⛔️ 过滤:房间不匹配 | msg.sid=%@ | curRoomId=%@",
// message.session.sessionId, @(self.roomInfo.roomId).stringValue);
// continue;
// }
// }
// }else {
NSLog(@"[Recv] ⛔️ 过滤:房间不匹配 | msg.sid=%@ | curRoomId=%@",
message.session.sessionId, @(self.roomInfo.roomId).stringValue);
continue;
// }
}
NSLog(@"[Recv] --- Message Raw Attach Content: %@, %@, %ld", @(message.senderClientType), message.rawAttachContent, (long)message.messageType);
@@ -1948,19 +1960,19 @@ XPCandyTreeInsufficientBalanceViewDelegate>
[self handleNIMNotificationTypeMessage:message];
} else if (message.messageType == NIMMessageTypeCustom) {
// first/second/size3
//#if DEBUG
// if ([message.messageObject isKindOfClass:[NIMCustomObject class]]) {
// NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
// if ([obj.attachment isKindOfClass:[AttachmentModel class]]) {
// AttachmentModel *att = (AttachmentModel *)obj.attachment;
// NSData *payloadJSON = nil;
// @try { payloadJSON = [NSJSONSerialization dataWithJSONObject:att.data ?: @{} options:0 error:nil]; } @catch (__unused NSException *e) {}
// NSLog(@"[Recv] 🎯 自定义消息 | first=%ld second=%ld | payload=%lub | sid=%@ | ts=%.3f",
// (long)att.first, (long)att.second, (unsigned long)payloadJSON.length,
// message.session.sessionId, [[NSDate date] timeIntervalSince1970]);
// }
// }
//#endif
#if DEBUG
if ([message.messageObject isKindOfClass:[NIMCustomObject class]]) {
NIMCustomObject *obj = (NIMCustomObject *)message.messageObject;
if ([obj.attachment isKindOfClass:[AttachmentModel class]]) {
AttachmentModel *att = (AttachmentModel *)obj.attachment;
NSData *payloadJSON = nil;
@try { payloadJSON = [NSJSONSerialization dataWithJSONObject:att.data ?: @{} options:0 error:nil]; } @catch (__unused NSException *e) {}
NSLog(@"[Recv] 🎯 自定义消息 | first=%ld second=%ld | payload=%lub | sid=%@ | ts=%.3f",
(long)att.first, (long)att.second, (unsigned long)payloadJSON.length,
message.session.sessionId, [[NSDate date] timeIntervalSince1970]);
}
}
#endif
[self handleNimCustomTypeMessage:message];
} else if(message.messageType == NIMMessageTypeText) {
[self.messageContainerView handleNIMTextMessage:message];
@@ -3239,9 +3251,32 @@ XPCandyTreeInsufficientBalanceViewDelegate>
}
// 使
[self.messageContainerView handleNIMCustomMessage:message];
// [self.messageContainerView handleNIMCustomMessage:message];
// [self.animationView handleNIMCustomMessage:message];
// [self handleNimCustomTypeMessage:message];
// [self onRecvMessages:@[message]];
NSLog(@"XPRoomViewController: 处理公共房间转发的106类型消息");
switch (message.messageType) {
case NIMMessageTypeNotification:
[self handleNIMNotificationTypeMessage:message];
break;
case NIMMessageTypeCustom:
[self handleNimCustomTypeMessage:message];
break;
case NIMMessageTypeText:
[self.messageContainerView handleNIMTextMessage:message];
[self.littleGameView handleNIMTextMessage:message];
break;
case NIMMessageTypeTip:
[self.messageContainerView handleNIMTextMessage:message];
break;
case NIMMessageTypeImage:
[self.messageContainerView handleNIMImageMessage:message];
break;
default:
break;
}
}
@end