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 3 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(recieveNewMsgForOutLength) name:LCCKNotificationTextOutLength object:nil];

[self.chatViewModel setDefaultBackgroundImage];
self.navigationItem.title = LCCKLocalizedStrings(@"Chat");//@"聊天";
!self.viewDidLoadBlock ?: self.viewDidLoadBlock(self);
Expand Down Expand Up @@ -410,6 +418,17 @@ - (void)makeSureSendValidMessage:(id)message afterFetchedConversationShouldWithA
}
}

#pragma mark - Notification
- (void)userWillSendMsgWithoutPower {
//FIXME:放开方法
// [self showWarning:@"需要开启麦克风权限"];
}

- (void)recieveNewMsgForOutLength {
//FIXME:放开方法
// [self showWarning:@"每次输入最多1000字~"];
}

#pragma mark - UI init

- (void)initBarButton {
Expand Down
68 changes: 62 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 outTime;//是否超时
Copy link
Contributor

Choose a reason for hiding this comment

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

是不是用 timeout / timedOut / isTimedOut 之类的作为属性名更好?

Copy link
Author

Choose a reason for hiding this comment

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

好的


#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:@"LCCKChatBarRecordVoiceOutTime" object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
Expand Down Expand Up @@ -345,7 +348,8 @@ - (void)endConvertWithMP3FileName:(NSString *)fileName {
}

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

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

- (void)setup {
self.close = NO;
self.outTime = NO;
self.oldTextViewHeight = kLCCKChatBarTextViewFrameMinHeight;
self.allowTextViewContentOffset = YES;
self.MP3 = [[Mp3Recorder alloc] initWithDelegate:self];
Expand All @@ -494,6 +499,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:@"LCCKChatBarRecordVoiceOutTime" 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 +513,29 @@ - (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];
}
}

- (BOOL)JudgeAVAudioSession {
Copy link
Contributor

Choose a reason for hiding this comment

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

这个方法名应该以小写字母开头。

Copy link
Author

Choose a reason for hiding this comment

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

好的

__block BOOL bCanRecord = YES;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
if ([audioSession respondsToSelector:@selector(requestRecordPermission:)]) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ChatKit 支持 iOS 7 及以上,-[AVAudioSession requestRecordPermission:] 在 iOS 7 上是可用的,可以直接调用。

Copy link
Author

Choose a reason for hiding this comment

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

我看看 这个修改本来只是自己项目里用 不小心提过来了

[audioSession performSelector:@selector(requestRecordPermission:) withObject:^(BOOL granted) {
if (granted) {
bCanRecord = YES;
} else {
bCanRecord = NO;
}
}];
}
return bCanRecord;
}

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

/**
* 更新录音显示状态,手指向上滑动后提示松开取消录音
*/
Expand All @@ -539,6 +571,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.outTime = YES;
}
}

- (void)setShowType:(LCCKFunctionViewShowType)showType {
if (_showType == showType) {
return;
Expand Down Expand Up @@ -664,6 +716,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:LCCKNotificationTextOutLength object:nil];
return;
}
if (self.delegate && [self.delegate respondsToSelector:@selector(chatBar:sendMessage:)]) {
[self.delegate chatBar:self sendMessage:text];
}
Expand Down
14 changes: 12 additions & 2 deletions ChatKit/Class/Module/Conversation/View/ChatBar/LCCKProgressHUD.m
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,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:@"LCCKChatBarRecordVoiceOutTime" object:nil];
[_timer invalidate];
_timer = nil;
}
}

[UIView commitAnimations];
}

Expand Down Expand Up @@ -128,7 +138,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
11 changes: 11 additions & 0 deletions ChatKit/Class/Tool/LCCKConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ static NSString *const LCCKBadgeTextForNumberGreaterThanLimit = @"···";
/// @name Notification Name
///=============================================================================


/**
* 发送语音消息没有权限。通知界面提醒用户
*/
static NSString *const LCCKNotificationRecordNoPower = @"LCCKChatBarRecordVoiceNoPower";

/**
* 发送文本消息过长。通知界面提醒用户
*/
static NSString *const LCCKNotificationTextOutLength = @"LCCKChatBarTextOutLength";

/**
* 未读数改变了。通知去服务器同步 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