保存输入框状态

一、在 viewWillAppear 的时候获取到输入框状态,然后设置给 defaultInputType。

// 设置输入框默认样式
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.defaultInputType = [self getInputStatus];
}


// 代码中 RCDIMService 为全局单例类
- (RCChatSessionInputBarInputType)getInputStatus {
    NSString *userInputStatusKey =
        [NSString stringWithFormat:@"%lu--%@", (unsigned long)self.conversationType, self.targetId];
    NSMutableDictionary *userInputStatus = [RCDIMService sharedService].userInputStatus;
    if (userInputStatus && [userInputStatus.allKeys containsObject:userInputStatusKey]) {
        KBottomBarStatus inputType = (KBottomBarStatus)[userInputStatus[userInputStatusKey] integerValue];
        //输入框记忆功能,如果退出时是语音输入,再次进入默认语音输入
        if (inputType == KBottomBarRecordStatus) {
            return RCChatSessionInputBarInputVoice;
        } else if (inputType == KBottomBarPluginStatus) {
            //      self.defaultInputType = RCChatSessionInputBarInputExtention;
        } else if (inputType == KBottomBarBurnStatus) {
            return RCChatSessionInputBarInputBurnMode;
        }
    }
    return 0;
}

二、在 viewWillDisappear 的时候保存输入框状态到一个全局存在的字典中。

// 输入框状态保存
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self saveInputStatus];
}

- (void)saveInputStatus {
    KBottomBarStatus inputType = self.chatSessionInputBarControl.currentBottomBarStatus;
    if (self.chatSessionInputBarControl.burnMessageMode) {
        inputType = KBottomBarBurnStatus;
    }
    NSMutableDictionary *userInputStatus = [RCDIMService sharedService].userInputStatus; 
    if (!userInputStatus) {
        userInputStatus = [NSMutableDictionary new];
    }
    NSString *userInputStatusKey =
        [NSString stringWithFormat:@"%lu--%@", (unsigned long)self.conversationType, self.targetId];
    [userInputStatus setObject:[NSString stringWithFormat:@"%ld", (long)inputType] forKey:userInputStatusKey];
}