diff --git a/ChatKit/Class/Module/Conversation/Controller/LCCKConversationViewController.m b/ChatKit/Class/Module/Conversation/Controller/LCCKConversationViewController.m index 8f2fea1b..891af78b 100644 --- a/ChatKit/Class/Module/Conversation/Controller/LCCKConversationViewController.m +++ b/ChatKit/Class/Module/Conversation/Controller/LCCKConversationViewController.m @@ -185,6 +185,10 @@ - (void)setup { } } +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + #ifdef CYLDebugging - (BOOL)willDealloc { if (![super willDealloc]) { @@ -221,6 +225,10 @@ - (void)viewDidLoad { [[LCCKUserSystemService sharedInstance] fetchCurrentUserInBackground:^(id user, NSError *error) { self.user = user; }]; + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userWillSendMsgWithoutPower) name:LCCKNotificationRecordNoPower object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(recieveNewMsgForLengthOut) name:LCCKNotificationTextLengthOut object:nil]; + [self.chatViewModel setDefaultBackgroundImage]; self.navigationItem.title = LCCKLocalizedStrings(@"Chat");//@"聊天"; !self.viewDidLoadBlock ?: self.viewDidLoadBlock(self); @@ -410,6 +418,28 @@ - (void)makeSureSendValidMessage:(id)message afterFetchedConversationShouldWithA } } +#pragma mark - Notification + +- (void)userWillSendMsgWithoutPower { + [self showWaring:@"需要开启麦克风权限"]; +} + +- (void)recieveNewMsgForLengthOut { + [self showWaring:@"每次输入最多1000字~"]; +} + +- (void)showWaring:(NSString *)message { + // 没有找到Toast 只能用弹框 + LCCKAlertController *alert = [LCCKAlertController alertControllerWithTitle:nil + message:message + preferredStyle:LCCKAlertControllerStyleAlert]; + NSString *cancelActionTitle = LCCKLocalizedStrings(@"ok"); + LCCKAlertAction *cancelAction = [LCCKAlertAction actionWithTitle:cancelActionTitle style:LCCKAlertActionStyleDefault + handler:^(LCCKAlertAction * action) {}]; + [alert addAction:cancelAction]; + [alert showWithSender:nil controller:self animated:YES completion:NULL]; +} + #pragma mark - UI init - (void)initBarButton { diff --git a/ChatKit/Class/Module/Conversation/View/ChatBar/LCCKChatBar.m b/ChatKit/Class/Module/Conversation/View/ChatBar/LCCKChatBar.m index 57a4bb04..2bcedbd9 100644 --- a/ChatKit/Class/Module/Conversation/View/ChatBar/LCCKChatBar.m +++ b/ChatKit/Class/Module/Conversation/View/ChatBar/LCCKChatBar.m @@ -45,6 +45,7 @@ @interface LCCKChatBar () 1000) { + [[NSNotificationCenter defaultCenter] postNotificationName:LCCKNotificationTextLengthOut object:nil]; + return; + } if (self.delegate && [self.delegate respondsToSelector:@selector(chatBar:sendMessage:)]) { [self.delegate chatBar:self sendMessage:text]; } diff --git a/ChatKit/Class/Module/Conversation/View/ChatBar/LCCKProgressHUD.m b/ChatKit/Class/Module/Conversation/View/ChatBar/LCCKProgressHUD.m index be1ba144..cf19e36f 100644 --- a/ChatKit/Class/Module/Conversation/View/ChatBar/LCCKProgressHUD.m +++ b/ChatKit/Class/Module/Conversation/View/ChatBar/LCCKProgressHUD.m @@ -8,6 +8,7 @@ #import "LCCKProgressHUD.h" #import "UIImage+LCCKExtension.h" +#import "LCCKConstants.h" @interface LCCKProgressHUD () @@ -73,7 +74,17 @@ - (void)timerAction { } else { self.centerLabel.textColor = [UIColor yellowColor]; } - self.centerLabel.text = [NSString stringWithFormat:@"%.1f",second-0.1]; + //修复录音时长恰好为1S时 提示中显示“-1”的问题 + if (second>0) { + self.centerLabel.text = [NSString stringWithFormat:@"%.1f",second-0.1]; + } else { + if (_timer) { + [[NSNotificationCenter defaultCenter] postNotificationName:LCCKNotificationRecordTimeOut object:nil]; + [_timer invalidate]; + _timer = nil; + } + } + [UIView commitAnimations]; } @@ -128,7 +139,7 @@ - (void)setProgressState:(LCCKProgressState)progressState { self.centerLabel.text = @"录音成功"; break; case LCCKProgressShort: - self.centerLabel.text = @"时间太短,请重试"; + self.centerLabel.text = @"时间太短";//文本过长 无法显示 break; case LCCKProgressError: self.centerLabel.text = @"录音失败"; diff --git a/ChatKit/Class/Module/Conversation/View/ChatMessageCell/LCCKChatMessageCell.m b/ChatKit/Class/Module/Conversation/View/ChatMessageCell/LCCKChatMessageCell.m index f65577b5..fe7b9f8b 100644 --- a/ChatKit/Class/Module/Conversation/View/ChatMessageCell/LCCKChatMessageCell.m +++ b/ChatKit/Class/Module/Conversation/View/ChatMessageCell/LCCKChatMessageCell.m @@ -398,7 +398,9 @@ - (UIImageView *)avatarImageView { if (avatarImageViewCornerRadiusBlock) { CGSize avatarImageViewSize = CGSizeMake(kAvatarImageViewWidth, kAvatarImageViewHeight); CGFloat avatarImageViewCornerRadius = avatarImageViewCornerRadiusBlock(avatarImageViewSize); - self.avatarImageView.lcck_cornerRadius = avatarImageViewCornerRadius; + //导致CPU消耗达到100% 暂时替换 + self.avatarImageView.layer.cornerRadius = avatarImageViewCornerRadius; + self.avatarImageView.clipsToBounds = YES; } [self bringSubviewToFront:_avatarImageView]; } diff --git a/ChatKit/Class/Tool/LCCKConstants.h b/ChatKit/Class/Tool/LCCKConstants.h index e11971c7..4d224644 100644 --- a/ChatKit/Class/Tool/LCCKConstants.h +++ b/ChatKit/Class/Tool/LCCKConstants.h @@ -70,6 +70,22 @@ static NSString *const LCCKBadgeTextForNumberGreaterThanLimit = @"···"; /// @name Notification Name ///============================================================================= + +/** + * 发送语音消息没有权限。通知界面提醒用户 + */ +static NSString *const LCCKNotificationRecordNoPower = @"LCCKChatBarRecordVoiceNoPower"; + +/** + * 发送文本消息过长。通知界面提醒用户 + */ +static NSString *const LCCKNotificationTextLengthOut = @"LCCKChatBarTextLengthOut"; + +/** + * 发送语音消息倒计时结束。通知UI停止动效 + */ +static NSString *const LCCKNotificationRecordTimeOut = @"LCCKChatBarRecordVoiceTimeOut"; + /** * 未读数改变了。通知去服务器同步 installation 的badge */ diff --git a/ChatKit/Class/Tool/Vendor/VoiceLib/Mp3Recorder.m b/ChatKit/Class/Tool/Vendor/VoiceLib/Mp3Recorder.m index fd0ba562..4c26721f 100755 --- a/ChatKit/Class/Tool/Vendor/VoiceLib/Mp3Recorder.m +++ b/ChatKit/Class/Tool/Vendor/VoiceLib/Mp3Recorder.m @@ -86,9 +86,8 @@ - (void)stopRecord if (cTime > 1) { [self audio_PCMtoMP3]; } else { - [_recorder deleteRecording]; - + // 时长小于1调用failRecord if ([_delegate respondsToSelector:@selector(failRecord)]) { [_delegate failRecord]; }