diff --git a/Example/MessageDisplayKitLeanchatExample/MessageDisplayKitLeanchatExample/Sections/Pages/IM/LeanChatMessageTableViewController.m b/Example/MessageDisplayKitLeanchatExample/MessageDisplayKitLeanchatExample/Sections/Pages/IM/LeanChatMessageTableViewController.m index 44ffa5c..f5a8f89 100644 --- a/Example/MessageDisplayKitLeanchatExample/MessageDisplayKitLeanchatExample/Sections/Pages/IM/LeanChatMessageTableViewController.m +++ b/Example/MessageDisplayKitLeanchatExample/MessageDisplayKitLeanchatExample/Sections/Pages/IM/LeanChatMessageTableViewController.m @@ -120,7 +120,15 @@ - (void)viewDidLoad }]; } }]; +} + +// 这里也要把 setupDidReceiveTypedMessageCompletion 放到 viewDidAppear 中 +// 不然, 就会冲突, 导致不能实时接收到对方的消息 +- (void)viewDidAppear:(BOOL)animated +{ + [super viewDidAppear:animated]; + WEAKSELF [[LeanChatManager manager] setupDidReceiveTypedMessageCompletion:^(AVIMConversation *conversation, AVIMTypedMessage *message) { // 富文本信息 if([conversation.conversationId isEqualToString:self.conversation.conversationId]){ @@ -129,6 +137,11 @@ - (void)viewDidLoad }]; } +- (void)viewDidDisappear:(BOOL)animated { + [super viewDidDisappear:animated]; + [[LeanChatManager manager] setupDidReceiveTypedMessageCompletion:nil]; +} + - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning];