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 */; };
18B1A36F2CE1E12800DD4A7C /* BleManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BleManager.swift; sourceTree = "<group>"; };
18B1A3722CE1EF4900DD4A7C /* BleChatVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BleChatVC.swift; sourceTree = "<group>"; };
18B1A3742CE1EF6200DD4A7C /* PhoneChatVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PhoneChatVC.swift; sourceTree = "<group>"; };
+ 18B4807F2D06A11D00E8171F /* LogVC.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LogVC.swift; sourceTree = "<group>"; };
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; };
18204BD32C193F9A00F94E69 /* AppDelegate.swift */,
18204BD52C193F9A00F94E69 /* SceneDelegate.swift */,
1843A7952C4E060D00FC010F /* LogViewController.swift */,
+ 18B4807F2D06A11D00E8171F /* LogVC.swift */,
18204BD72C193F9A00F94E69 /* ViewController.swift */,
18B1A36F2CE1E12800DD4A7C /* BleManager.swift */,
18B1A3742CE1EF6200DD4A7C /* PhoneChatVC.swift */,
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 */,
);
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 = "要使用麦克风录音哦";
);
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 = "要使用麦克风录音哦";
/// 开始扫描
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)
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)
}
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
--- /dev/null
+//
+// 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)
+ }
+}
+////
+//// 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)
+//
+// }
+//}
@objc func logAction(){
guard let nc = window?.rootViewController as? UINavigationController else {return}
- let vc = LogViewController()
+ let vc = LogVC()
nc.pushViewController(vc, animated: true)
}
import Foundation
/// 日记管理
-class Logger {
+public class Logger {
static var isDebug: Bool = false
fileprivate static let shared = 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))]: ")