Skip to content
This repository has been archived by the owner on Jul 2, 2019. It is now read-only.

修复一系列测试提出的Bug; #323

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ - (void)setup {
}
}

- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

#ifdef CYLDebugging
- (BOOL)willDealloc {
if (![super willDealloc]) {
Expand Down Expand Up @@ -221,6 +225,10 @@ - (void)viewDidLoad {
[[LCCKUserSystemService sharedInstance] fetchCurrentUserInBackground:^(id<LCCKUserDelegate> 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);
Expand Down Expand Up @@ -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 {
Expand Down
66 changes: 60 additions & 6 deletions ChatKit/Class/Module/Conversation/View/ChatBar/LCCKChatBar.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ @interface LCCKChatBar () <UITextViewDelegate, UINavigationControllerDelegate, M
@property (assign, nonatomic) CGFloat oldTextViewHeight;
@property (nonatomic, assign, getter=shouldAllowTextViewContentOffset) BOOL allowTextViewContentOffset;
@property (nonatomic, assign, getter=isClosed) BOOL close;
@property (nonatomic, assign) BOOL isTimeOut;//是否超时

#pragma mark - MessageInputView Customize UI
///=============================================================================
Expand Down Expand Up @@ -123,6 +124,8 @@ - (void)setupConstraints {
- (void)dealloc {
self.delegate = nil;
_faceView.delegate = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:LCCKNotificationRecordTimeOut object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
Expand Down Expand Up @@ -246,6 +249,19 @@ - (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
#pragma mark -
#pragma mark - Private Methods

- (BOOL)judgeAVAudioSession {
__block BOOL bCanRecord = YES;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession requestRecordPermission:^(BOOL granted) {
if (granted) {
bCanRecord = YES;
} else {
bCanRecord = NO;
}
}];
return bCanRecord;
}

- (void)updateChatBarConstraintsIfNeeded {
NSString *reason = [NSString stringWithFormat:@"🔴类名与方法名:%@(在第%@行),描述:%@", @(__PRETTY_FUNCTION__), @(__LINE__), @"Should update on main thread"];
NSAssert([NSThread mainThread], reason);
Expand Down Expand Up @@ -345,7 +361,8 @@ - (void)endConvertWithMP3FileName:(NSString *)fileName {
}

- (void)failRecord {
[LCCKProgressHUD dismissWithProgressState:LCCKProgressError];
// 此回调在录音时长小于1时调用 应该提示Short而不是Error
[LCCKProgressHUD dismissWithProgressState:LCCKProgressShort];
}

- (void)beginConvert {
Expand Down Expand Up @@ -474,6 +491,7 @@ - (UIView *)inputBarBackgroundView {

- (void)setup {
self.close = NO;
self.isTimeOut = NO;
self.oldTextViewHeight = kLCCKChatBarTextViewFrameMinHeight;
self.allowTextViewContentOffset = YES;
self.MP3 = [[Mp3Recorder alloc] initWithDelegate:self];
Expand All @@ -494,6 +512,10 @@ - (void)setup {
make.left.and.right.and.top.equalTo(self.inputBarBackgroundView);
make.height.mas_equalTo(.5f);
}];

//修复录音时点击Home键 在返回App后 仍然显示录音动效的问题
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appBecomeBackgroundCancelRecordVoice) name:UIApplicationDidEnterBackgroundNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appRecieveMsgFromRecordTimer) name:LCCKNotificationRecordTimeOut object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
self.backgroundColor = self.messageInputViewBackgroundColor;
Expand All @@ -504,9 +526,14 @@ - (void)setup {
* 开始录音
*/
- (void)startRecordVoice {
[LCCKProgressHUD show];
self.voiceRecordButton.highlighted = YES;
[self.MP3 startRecord];
// 判断权限
if ([self judgeAVAudioSession]) {
[LCCKProgressHUD show];
self.voiceRecordButton.highlighted = YES;
[self.MP3 startRecord];
} else {
[[NSNotificationCenter defaultCenter] postNotificationName:LCCKNotificationRecordNoPower object:nil];
}
}

/**
Expand All @@ -522,9 +549,12 @@ - (void)cancelRecordVoice {
* 录音结束
*/
- (void)confirmRecordVoice {
[self.MP3 stopRecord];
if (self.isTimeOut == NO) {
[self.MP3 stopRecord];
} else {
self.isTimeOut = NO;
}
}

/**
* 更新录音显示状态,手指向上滑动后提示松开取消录音
*/
Expand All @@ -539,6 +569,26 @@ - (void)updateContinueRecordVoice {
[LCCKProgressHUD changeSubTitle:@"向上滑动取消录音"];
}

/**
* 进入后台 取消当前的录音
*/
- (void)appBecomeBackgroundCancelRecordVoice {
[self cancelRecordVoice];
}

/**
* 倒计时结束 完成当前的录音
*/
- (void)appRecieveMsgFromRecordTimer
{
if (self.voiceRecordButton.highlighted == YES) {
self.voiceRecordButton.selected = NO;
self.voiceRecordButton.highlighted = NO;
[self.MP3 stopRecord];
self.isTimeOut = YES;
}
}

- (void)setShowType:(LCCKFunctionViewShowType)showType {
if (_showType == showType) {
return;
Expand Down Expand Up @@ -664,6 +714,10 @@ - (void)sendTextMessage:(NSString *)text{
if (!text || text.length == 0 || [text lcck_isSpace]) {
return;
}
if (text.length > 1000) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

您好,请把这个数字作为一个常量,放在 LCCKConstants.h 中,例如:

static const NSUInteger kLCCKMessageMaxTextLength = 1000;

然后在 alert 中也用这个常量来构造提示信息。

[[NSNotificationCenter defaultCenter] postNotificationName:LCCKNotificationTextLengthOut object:nil];
return;
}
if (self.delegate && [self.delegate respondsToSelector:@selector(chatBar:sendMessage:)]) {
[self.delegate chatBar:self sendMessage:text];
}
Expand Down
15 changes: 13 additions & 2 deletions ChatKit/Class/Module/Conversation/View/ChatBar/LCCKProgressHUD.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "LCCKProgressHUD.h"
#import "UIImage+LCCKExtension.h"
#import "LCCKConstants.h"

@interface LCCKProgressHUD ()

Expand Down Expand Up @@ -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];
}

Expand Down Expand Up @@ -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 = @"录音失败";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
16 changes: 16 additions & 0 deletions ChatKit/Class/Tool/LCCKConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
3 changes: 1 addition & 2 deletions ChatKit/Class/Tool/Vendor/VoiceLib/Mp3Recorder.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ - (void)stopRecord
if (cTime > 1) {
[self audio_PCMtoMP3];
} else {

[_recorder deleteRecording];

// 时长小于1调用failRecord
if ([_delegate respondsToSelector:@selector(failRecord)]) {
[_delegate failRecord];
}
Expand Down