/// 日记管理
class Logger {
- static var isDebug: Bool = true
+ static var isDebug: Bool = false
fileprivate static let shared = Logger()
private var fileHandle:FileHandle?
let path = foldPath + "\(Date().format(.middle)).log"
if !FileManager.default.fileExists(atPath: path) {
FileManager.default.createFile(atPath: path, contents: nil, attributes: nil)
+
}
return path
}
private let userDefaults = UserDefaults.standard
func saveList(_ list: [ChatCellModel]) {
+ let maxLength = 10000
var fullList = [ChatCellModel]()
fullList.append(contentsOf: list)
- if fullList.count > 1000{
- fullList = Array(fullList.dropFirst(fullList.count - 1000))
+ if fullList.count > maxLength{
+ fullList = Array(fullList.dropFirst(fullList.count - maxLength))
}
fullList = fullList.filter({$0.content.isNotEmpty})
let filePath = DCFolder.chatCache
do {
try encoder.write(to: URL(fileURLWithPath: filePath), options:.atomic)
+ Logger.debug("记录保存成功",filePath)
} catch {
Logger.debug("记录保存失败",filePath,error)
}
}
return []
}
+ func LargeDateDemoSave(){
+ var list = [ChatCellModel]()
+ for i in 0..<10000 {
+ var model = ChatCellModel()
+ model.content = "这是第\(i)数据,jhjah测试数据都是大健康大是的撒辅导费大概大地方佛挡杀佛水电费,电风扇发多少的,防守打法第三方都是佛挡杀佛水电费神鼎飞丹砂方式发到水电费递四方速递咕嘟咕嘟发给电饭锅发的鬼地方"
+ model.type = i%2
+ model.id = i
+ list.append(model)
+ }
+ saveList(list)
+ }
}
///结束对话,但并不会终止正在播放的录音
JoyGemChatManager.shared().stopChat()
- ChatCache.shared.saveList(JoySdkManager.shared.dataList)
+
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
refreshData()
}
+ override func viewDidDisappear(_ animated: Bool) {
+ super.viewDidDisappear(animated)
+ ChatCache.shared.saveList(JoySdkManager.shared.dataList)
+ }
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if (keyPath == "isActive") {
let isOpen = change?[NSKeyValueChangeKey.newKey] as? Bool
App.shared.goToPage(BleScanVC())
// App.shared.goToPage(CalendarPickerVC())
// BleManager.shared.checkSettingsConnected()
+// ChatCache.shared.LargeDateDemoSave()
}
@objc func editAction(){
let vc = BackgroundVC()
guard let version = version else{
return
}
- startCheck(deviceName: deviceName, version: "1.1.0")
+ startCheck(deviceName: deviceName, version: version)
}
}
}
let formatter = DateFormatter()
formatter.dateFormat = "yyyyMMddHHmmss"
let name = formatter.string(from: Date())
+ let app_version = Bundle.main.appVersion ?? "1.0.0" + "_"
+ let build_version = Bundle.main.appBuild ?? "1"
+ let version = "\(app_version)_\(build_version)"
- let filePath = "\(NSHomeDirectory())/Documents/DeepChords_\(name).txt"
+ let fileName = "DeepChords_" + version + "_\(name).txt"
+
+ let filePath = "\(NSHomeDirectory())/Documents/\(fileName)"
let url = URL(fileURLWithPath: filePath)
let data = self.textView.text.data(using:.utf8)
do {