From: liangzhenying <867174124@qq.com> Date: Mon, 9 Dec 2024 07:54:15 +0000 (+0800) Subject: 设备管理类日志输出也添加到日志管理 X-Git-Url: http://git.snicker.com.cn/sitemap.xml?a=commitdiff_plain;h=b1378886782ba6257d33a3ea8a9e49487adf40a9;p=mirrors%2FVoiceChatSdk_iOS.git 设备管理类日志输出也添加到日志管理 --- diff --git a/MixSdk/Example/Example.xcodeproj/project.pbxproj b/MixSdk/Example/Example.xcodeproj/project.pbxproj index 3db5e89..08a7ce3 100644 --- a/MixSdk/Example/Example.xcodeproj/project.pbxproj +++ b/MixSdk/Example/Example.xcodeproj/project.pbxproj @@ -24,6 +24,7 @@ 18B1A3702CE1E12800DD4A7C /* BleManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18B1A36F2CE1E12800DD4A7C /* BleManager.swift */; }; 18B1A3732CE1EF4900DD4A7C /* BleChatVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18B1A3722CE1EF4900DD4A7C /* BleChatVC.swift */; }; 18B1A3752CE1EF6200DD4A7C /* PhoneChatVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18B1A3742CE1EF6200DD4A7C /* PhoneChatVC.swift */; }; + 18B480812D06A11D00E8171F /* LogVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18B4807F2D06A11D00E8171F /* LogVC.swift */; }; 18C42C802C242AAC000D8860 /* liblzma.5.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 18C42C7E2C242AAC000D8860 /* liblzma.5.tbd */; }; 18C42C822C242AD3000D8860 /* CoreAudio.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 18C42C812C242AD3000D8860 /* CoreAudio.framework */; }; 18C42C842C242B01000D8860 /* libiconv.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 18C42C832C242B01000D8860 /* libiconv.tbd */; }; @@ -65,6 +66,7 @@ 18B1A36F2CE1E12800DD4A7C /* BleManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BleManager.swift; sourceTree = ""; }; 18B1A3722CE1EF4900DD4A7C /* BleChatVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BleChatVC.swift; sourceTree = ""; }; 18B1A3742CE1EF6200DD4A7C /* PhoneChatVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhoneChatVC.swift; sourceTree = ""; }; + 18B4807F2D06A11D00E8171F /* LogVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LogVC.swift; sourceTree = ""; }; 18C42C7E2C242AAC000D8860 /* liblzma.5.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = liblzma.5.tbd; path = usr/lib/liblzma.5.tbd; sourceTree = SDKROOT; }; 18C42C812C242AD3000D8860 /* CoreAudio.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreAudio.framework; path = System/Library/Frameworks/CoreAudio.framework; sourceTree = SDKROOT; }; 18C42C832C242B01000D8860 /* libiconv.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libiconv.tbd; path = usr/lib/libiconv.tbd; sourceTree = SDKROOT; }; @@ -134,6 +136,7 @@ 18204BD32C193F9A00F94E69 /* AppDelegate.swift */, 18204BD52C193F9A00F94E69 /* SceneDelegate.swift */, 1843A7952C4E060D00FC010F /* LogViewController.swift */, + 18B4807F2D06A11D00E8171F /* LogVC.swift */, 18204BD72C193F9A00F94E69 /* ViewController.swift */, 18B1A36F2CE1E12800DD4A7C /* BleManager.swift */, 18B1A3742CE1EF6200DD4A7C /* PhoneChatVC.swift */, @@ -340,6 +343,7 @@ 1843A7962C4E060D00FC010F /* LogViewController.swift in Sources */, 18EBBA152CDE1791006F3B80 /* VoiceChatCell.swift in Sources */, 18068D022CDCC57C006B6EF5 /* PcmPlayer.swift in Sources */, + 18B480812D06A11D00E8171F /* LogVC.swift in Sources */, 18B1A3732CE1EF4900DD4A7C /* BleChatVC.swift in Sources */, 18204BD42C193F9A00F94E69 /* AppDelegate.swift in Sources */, 18B1A3752CE1EF6200DD4A7C /* PhoneChatVC.swift in Sources */, @@ -512,7 +516,7 @@ ); GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = Example/Info.plist; - INFOPLIST_KEY_CFBundleDisplayName = VoiceChat; + INFOPLIST_KEY_CFBundleDisplayName = VoiceChatDemo; INFOPLIST_KEY_LSApplicationCategoryType = ""; INFOPLIST_KEY_NSBluetoothAlwaysUsageDescription = "需要开启蓝牙功能"; INFOPLIST_KEY_NSMicrophoneUsageDescription = "要使用麦克风录音哦"; @@ -555,7 +559,7 @@ ); GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = Example/Info.plist; - INFOPLIST_KEY_CFBundleDisplayName = VoiceChat; + INFOPLIST_KEY_CFBundleDisplayName = VoiceChatDemo; INFOPLIST_KEY_LSApplicationCategoryType = ""; INFOPLIST_KEY_NSBluetoothAlwaysUsageDescription = "需要开启蓝牙功能"; INFOPLIST_KEY_NSMicrophoneUsageDescription = "要使用麦克风录音哦"; diff --git a/MixSdk/Example/Example/BleManager.swift b/MixSdk/Example/Example/BleManager.swift index 9773fe9..792c176 100644 --- a/MixSdk/Example/Example/BleManager.swift +++ b/MixSdk/Example/Example/BleManager.swift @@ -45,7 +45,7 @@ extension BleManager{ /// 开始扫描 func startScan() { print("开始扫描...") - centralManager.scanForPeripherals(withServices: nil) + centralManager.scanForPeripherals(withServices: nil, options: nil) // centralManager.scanForPeripherals(withServices: [CBUUID(string: kserviceUUID)], options: nil) if let peripheral = centralManager.retrieveConnectedPeripherals(withServices: [CBUUID(string: kserviceUUID)]).first{ discoverCallBack?(peripheral) @@ -127,7 +127,8 @@ extension BleManager: CBCentralManagerDelegate { func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) { currentPeripheral = peripheral peripheral.delegate = self - peripheral.discoverServices([CBUUID(string: kserviceUUID)]) +// peripheral.discoverServices([CBUUID(string: kserviceUUID)]) + peripheral.discoverServices(nil) didConnectedCallBack?(peripheral) } @@ -143,12 +144,16 @@ extension BleManager: CBCentralManagerDelegate { extension BleManager: CBPeripheralDelegate { func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) { + Logger.log("服务=",peripheral.services ?? []) + peripheral.services?.forEach { peripheral.discoverCharacteristics(nil, for: $0) } } func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) { + Logger.log("特征 ",service.characteristics ?? []) service.characteristics?.forEach { + Logger.log($0.uuid.uuidString) if $0.uuid.uuidString == kNotifyUUID { peripheral.setNotifyValue(true, for: $0) return diff --git a/MixSdk/Example/Example/LogVC.swift b/MixSdk/Example/Example/LogVC.swift new file mode 100644 index 0000000..8b02e77 --- /dev/null +++ b/MixSdk/Example/Example/LogVC.swift @@ -0,0 +1,62 @@ +// +// LogVC.swift +// IOT +// +// Created by incar on 2024/11/22. +// + + +import UIKit +import MSVoiceChatSdk +class LogVC: UIViewController { + + var textView = UITextView() + + override func viewDidLoad() { + title = "log" + view.backgroundColor = .white + self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "share", style: .done, target: self, action: #selector(shareAction)) + textView.isEditable = false + view.addSubview(textView) + textView.frame = CGRectMake(0, 100, view.bounds.size.width, view.bounds.size.height - 100) + } + + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + + textView.text = MSVoiceChatSdk.shared.logs.joined(separator: "\n") + let range = NSMakeRange(textView.text.count - 1, 1) + textView.scrollRangeToVisible(range) + } + + @objc func shareAction() { + let formatter = DateFormatter() + formatter.dateFormat = "MMddHHmmss" + let name = formatter.string(from: Date()) + + let filePath = "\(NSHomeDirectory())/Documents/StarburstSdk_\(name).txt" + let url = URL(fileURLWithPath: filePath) + let data = self.textView.text.data(using:.utf8) + do { + try data?.write(to: url, options:.atomic) + print(filePath) + self.saveFile(withFilePath: filePath) + } catch { + print(error) + } + } + + func saveFile(withFilePath filePath: String) { + let fUrl = URL(fileURLWithPath: filePath) + let vc = UIDocumentPickerViewController(url: fUrl, in:.exportToService) + vc.delegate = self + vc.modalPresentationStyle = .overFullScreen + self.present(vc, animated: true, completion: nil) + } +} + +extension LogVC:UIDocumentPickerDelegate{ + func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) { + controller.dismiss(animated: true, completion: nil) + } +} diff --git a/MixSdk/Example/Example/LogViewController.swift b/MixSdk/Example/Example/LogViewController.swift index b5dd193..ca57c2d 100644 --- a/MixSdk/Example/Example/LogViewController.swift +++ b/MixSdk/Example/Example/LogViewController.swift @@ -1,42 +1,42 @@ +//// +//// LogViewController.swift +//// Example +//// +//// Created by incar on 2024/7/22. +//// // -// LogViewController.swift -// Example +//import UIKit +//import MSVoiceChatSdk // -// Created by incar on 2024/7/22. +//class LogViewController: UIViewController { +// +// var textView = UITextView() // - -import UIKit -import MSVoiceChatSdk - -class LogViewController: UIViewController { - - var textView = UITextView() - - override func viewDidLoad() { - title = "log" - self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "clean", style: .done, target: self, action: #selector(cleanAction)) - - view.addSubview(textView) - textView.snp.makeConstraints { make in - make.top.equalToSuperview() - make.left.right.bottom.equalToSuperview() - } - } - - override func viewDidAppear(_ animated: Bool) { - super.viewDidAppear(animated) - - textView.text = MSVoiceChatSdk.shared.logs.joined(separator: "\n") - let range = NSMakeRange(textView.text.count - 1, 1) - textView.scrollRangeToVisible(range) - } - - @objc func cleanAction(){ - MSVoiceChatSdk.shared.cleanLog() - - textView.text = MSVoiceChatSdk.shared.logs.joined(separator: "\n") - let range = NSMakeRange(textView.text.count - 1, 1) - textView.scrollRangeToVisible(range) - - } -} +// override func viewDidLoad() { +// title = "log" +// self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "clean", style: .done, target: self, action: #selector(cleanAction)) +// +// view.addSubview(textView) +// textView.snp.makeConstraints { make in +// make.top.equalToSuperview() +// make.left.right.bottom.equalToSuperview() +// } +// } +// +// override func viewDidAppear(_ animated: Bool) { +// super.viewDidAppear(animated) +// +// textView.text = MSVoiceChatSdk.shared.logs.joined(separator: "\n") +// let range = NSMakeRange(textView.text.count - 1, 1) +// textView.scrollRangeToVisible(range) +// } +// +// @objc func cleanAction(){ +// MSVoiceChatSdk.shared.cleanLog() +// +// textView.text = MSVoiceChatSdk.shared.logs.joined(separator: "\n") +// let range = NSMakeRange(textView.text.count - 1, 1) +// textView.scrollRangeToVisible(range) +// +// } +//} diff --git a/MixSdk/Example/Example/SceneDelegate.swift b/MixSdk/Example/Example/SceneDelegate.swift index aeca1a0..b538a9c 100644 --- a/MixSdk/Example/Example/SceneDelegate.swift +++ b/MixSdk/Example/Example/SceneDelegate.swift @@ -31,7 +31,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { @objc func logAction(){ guard let nc = window?.rootViewController as? UINavigationController else {return} - let vc = LogViewController() + let vc = LogVC() nc.pushViewController(vc, animated: true) } diff --git a/MixSdk/MixSdk/MixSdk/Tools/Logger.swift b/MixSdk/MixSdk/MixSdk/Tools/Logger.swift index e309d5d..fc44144 100644 --- a/MixSdk/MixSdk/MixSdk/Tools/Logger.swift +++ b/MixSdk/MixSdk/MixSdk/Tools/Logger.swift @@ -8,7 +8,7 @@ import Foundation /// 日记管理 -class Logger { +public class Logger { static var isDebug: Bool = false fileprivate static let shared = Logger() @@ -43,7 +43,7 @@ class Logger { } extension Logger { - static func log(_ logs: Any..., line: Int = #line, separator: String = " ", terminator: String = "\n") { + public static func log(_ logs: Any..., line: Int = #line, separator: String = " ", terminator: String = "\n") { objc_sync_enter(Logger.shared) if Logger.isDebug { print(Logger.shared.dateString, terminator: " [MSVoiceChatSdk-\(String(format: "%03d", line))]: ")