修复频繁获取设备信息失败bug keyboard2
authorliangzhenying <867174124@qq.com>
Fri, 30 May 2025 08:34:40 +0000 (16:34 +0800)
committerliangzhenying <867174124@qq.com>
Fri, 30 May 2025 08:34:40 +0000 (16:34 +0800)
13 files changed:
MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist
MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.h
MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.m
MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m
MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.m
MouseSdk/AiMouseSdk/M8/M8MouseSdk.m
MouseSdk/AiMouseSdk/Manager/DeviceManger.m
MouseSdk/AiMouseSdk/Manager/LogManager.h
MouseSdk/AiMouseSdk/Manager/LogManager.m
MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m
MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate
MouseSdk/MouseSdk/ViewController.m
MouseSdk/Pods/Pods.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist

index 64bd978..6349347 100644 (file)
@@ -7,7 +7,7 @@
                <key>AiMouseSdk copy.xcscheme_^#shared#^_</key>
                <dict>
                        <key>orderHint</key>
-                       <integer>2</integer>
+                       <integer>3</integer>
                </dict>
                <key>AiMouseSdk.xcscheme_^#shared#^_</key>
                <dict>
index 2351512..4a562cb 100644 (file)
@@ -12,6 +12,7 @@
 NS_ASSUME_NONNULL_BEGIN
 
 @interface AiDeviceInfoManager : NSObject
+@property (nonatomic, strong) AiMouseDeviceInfo *deviceInfo;
 @property (nonatomic,strong)void (^sendToBleBlock)(NSData *data);
 @property (nonatomic,strong)void (^outputLogBlock)(NSString *log);
 @property (nonatomic,strong)void (^timeOutBlock)(void);
index 3b7f186..d4942d7 100644 (file)
@@ -31,7 +31,7 @@
 
 @interface AiDeviceInfoManager()<AiSenderDelegate>
 @property (nonatomic, strong) AiSender *sender;
-@property (nonatomic, strong) AiMouseDeviceInfo *deviceInfo;
+
 @property (nonatomic, strong) void (^deviceInfoBlock)(AiMouseDeviceInfo *deviceInfo,NSError *error);
 @property (nonatomic, strong) void (^getRSSIBlock)(NSString *value,NSError *error);
 @property (nonatomic, strong) void (^getVersionBlock)(NSString *version,NSError *error);
index 1df5a3f..1adf0b8 100644 (file)
@@ -28,6 +28,7 @@
 @end
 
 @interface AiMouseDeviceInfo()
+
 @property (nonatomic, strong) NSString *productKey;/// 品牌key
 @property (nonatomic, strong) NSString *secretKey;/// 品牌Secret
 @property (nonatomic, strong) NSString *deviceSecret;///设备Secret
@@ -40,6 +41,7 @@
 @end
 
 @interface AiMouse()
+@property (nonatomic, assign) BOOL isLoading;///是否正在请求
 @property (nonatomic, strong) NSMutableData *voiceData;
 @property (nonatomic, strong) SbcConverter *sbcTool;
 @property (nonatomic, strong) AiRecordManager *recordManager;
 -(instancetype)init{
     if (self = [super init]) {
         _connectType =  AiMouseConnectType_bluetooth;
-        self.voiceData = [[NSMutableData alloc] init];
         [self.recordManager checkPermissions];
     }
     return self;
 }
 
+-(NSMutableData *)voiceData{
+    if (_voiceData == nil) {
+        _voiceData = [[NSMutableData alloc] init];
+    }
+    return _voiceData;
+}
+
 
 -(AiDeviceInfoManager *)deviceInfoManager{
     if (!_deviceInfoManager) {
 }
 
 - (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo *deviceInfo,NSError *error))complete{
+    if (self.isLoading) {
+        complete(self.deviceInfoManager.deviceInfo,nil);
+        return;
+    }
+    self.isLoading = true;
+    dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC);
+    dispatch_after(delayTime, dispatch_get_main_queue(), ^{
+        self.isLoading = false;
+    });
     __weak typeof(self) ws = self;
     [self.deviceInfoManager getDeviceInfo:^(AiMouseDeviceInfo * _Nonnull deviceInfo, NSError * _Nonnull error) {
         if (deviceInfo && ([DeviceManger shared].appType == 2 || [DeviceManger shared].appType == 4)) {
                 deviceInfo.byteAuthInfo = info;
                 [ws showLog:deviceInfo.description];
                 complete(deviceInfo,error);
+                self.isLoading = false;
             }];
         }
         else{
 #pragma mark - other
 - (void)sendRecordData:(NSData *)data{
     //    [self showLog:[NSString stringWithFormat:@"[audio] %@",data]];
-    if ([DeviceManger shared].appType == 2 || [DeviceManger shared].appType == 4) {
+//    if ([DeviceManger shared].appType == 2 || [DeviceManger shared].appType == 4) {
         [self.voiceData appendData:data];
         if (self.voiceData.length > 5000) {
             if (self.delegate)  [self.delegate aiMouseSendRecordData:self.voiceData];
-            self.voiceData = [[NSMutableData alloc] init];
+            self.voiceData = nil;
         }
-    }
-    else{
-        if (self.delegate)  [self.delegate aiMouseSendRecordData:data];
-    }
+//    }
+//    else{
+//        if (self.delegate)  [self.delegate aiMouseSendRecordData:data];
+//    }
 }
 - (void)sendCmdData:(NSData *)data{
 //    [self showLog:[NSString stringWithFormat:@"[send] %@",data]];
 - (void)startRecord{
     //    [self showLog:@"开始录音"];
     [self.recordManager start];
-    self.voiceData = [[NSMutableData alloc] init];
 }
 
 - (void)stopRecord:(BOOL)sendCmd{
index fff141c..cb0ec49 100644 (file)
@@ -56,7 +56,7 @@
     
     self.info = [[ByteDanceInfo alloc] init];
     stb_app_start_identify();
-    [self performSelector:@selector(timeOutAction) withObject:nil afterDelay:5];
+    [self performSelector:@selector(timeOutAction) withObject:nil afterDelay:30];
 }
 
 - (void)timeOutAction{
index 183256d..7d75eb1 100644 (file)
@@ -21,7 +21,8 @@
 @property (nonatomic,strong)AiMouseDeviceInfo *fullInfo;
 @property (nonatomic,assign)NSInteger questTimes;
 
-@property (nonatomic,strong)NSMutableData *voiceData;
+@property (nonatomic,strong)NSMutableData *deviceData;
+@property (nonatomic, strong) NSMutableData *voiceData;
 @end
 
 @implementation M8MouseSdk
@@ -40,7 +41,7 @@
         _recordManager = [[AiRecordManager alloc] init];
         __weak typeof(self) ws = self;
         _recordManager.didRecordData = ^(NSData * _Nonnull data) {
-            [ws showLog:[NSString stringWithFormat:@"%@",data]];
+            ws.voiceData = [[NSMutableData alloc] init];
             [ws sendRecordData:data];
         };
     }
@@ -67,7 +68,7 @@
 - (void)switchConnect:(AiMouseConnectType)type isConnected:(BOOL)isConneted{
     [NSObject cancelPreviousPerformRequestsWithTarget:self];
     if(isConneted ){
-        self.voiceData = [[NSMutableData alloc] init];
+        self.deviceData = [[NSMutableData alloc] init];
         _connected = true;
         _connectType = type;
         [self showLog:type == AiMouseConnectType_bluetooth?@"sdk切换到蓝牙模式":@"sdk切换到usb模式"];
 }
 #pragma mark - ble
 - (void)bleReceiveAiData:(NSData *)data{
-    [self.voiceData appendData:data];
+    [self.deviceData appendData:data];
     [self convertToPcm];
 }
 
 - (void)convertToPcm{
-    if (self.voiceData.length >= 390) {
-        NSData *subData = [self.voiceData subdataWithRange:NSMakeRange(0, 390)];
+    if (self.deviceData.length >= 390) {
+        NSData *subData = [self.deviceData subdataWithRange:NSMakeRange(0, 390)];
         NSData *pcm = [self toPcm:subData];
-        self.voiceData = [NSMutableData dataWithData:[self.voiceData subdataWithRange:NSMakeRange(390, self.voiceData.length - 390)]];
+        self.deviceData = [NSMutableData dataWithData:[self.deviceData subdataWithRange:NSMakeRange(390, self.deviceData.length - 390)]];
         [self sendRecordData:pcm];
         [self convertToPcm];
     }
 }
 #pragma mark - other
 - (void)sendRecordData:(NSData *)data{
-//    [self showLog:[NSString stringWithFormat:@"[send][audio] %@",data]];
-    if (self.delegate)  [self.delegate m8MouseSendRecordData:data];
+    //    if ([DeviceManger shared].appType == 2 || [DeviceManger shared].appType == 4) {
+    [self.voiceData appendData:data];
+    if (self.voiceData.length > 5000) {
+        if (self.delegate)  [self.delegate m8MouseSendRecordData:self.voiceData];
+        self.voiceData = [[NSMutableData alloc] init];
+    }
+    //    }
+    //    else{
+    //        if (self.delegate)  [self.delegate m8MouseSendRecordData:data];
+    //    }
 }
 
 - (void)sendCmdData:(NSData *)data{
 }
 #pragma mark - deviceInfo
 - (void)startRecord{
+    self.voiceData = [[NSMutableData alloc] init];
     [self.recordManager start];
 }
 
index a3058f5..989b41c 100644 (file)
@@ -53,7 +53,7 @@
 - (instancetype)init{
     self = [super init];
     if (self) {
-        self.version = @"MouseSdk_v2025052701";
+        self.version = @"MouseSdk_v2025052901";
     }
     return self;
 }
 //@"08":@"08",
 /// 其他未定义
 - (void)m8MouseSendCmdData:(NSData *)data{
-    NSLog(@"%@",data);
     uint8 cmd;
     [data getBytes:&cmd length:1];
     if( cmd == 0x01){
 - (void)sendRecordingCallBackToApp:(NSData *)data{
     [self.recordData appendData:data];
     if (self.recordingCallBack) {
+        [self showLog:@"超过5000B,发送给app"];
         // 将NSData转换为Base64编码的字符串
         self.recordingCallBack( [data base64EncodedStringWithOptions:0]);
     }
index 440eeb3..e07cf95 100644 (file)
@@ -22,7 +22,5 @@
 
 - (void)saveLog:(NSString *)log;
 
-- (NSString *)getLogs;
-
 
 @end
index 0ba90fa..091d570 100644 (file)
@@ -9,7 +9,6 @@
 
 @interface LogManager()
 @property (nonatomic, strong) NSFileHandle *fileHandle;
-@property (nonatomic, strong) NSMutableArray *logList;
 @end
 
 
@@ -26,7 +25,6 @@
 
 - (instancetype)init {
     if (self = [super init]) {
-        self.logList = [[NSMutableArray alloc] init];
 
     }
     return self;
 }
 - (void)saveLog:(NSString *)log {
     [self.fileHandle writeData:[log dataUsingEncoding:NSUTF8StringEncoding]];
-    [self.logList addObject:log];
 }
 
-
-- (NSString *)getLogs{
-    //    NSData *data = [[NSData alloc] initWithContentsOfFile:[self getPath]];
-    //    NSString *log = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
-    //    return  log;
-    NSString *log = [self.logList componentsJoinedByString:@""];
-    return  log;
-}
 @end
index cb1b4f1..b2dc1e6 100644 (file)
@@ -25,7 +25,7 @@
 @end
 
 @interface TlwMouse()
-
+@property (nonatomic, strong) NSMutableData *voiceData;
 @property (nonatomic, strong) AiRecordManager *recordManager;
 
 @property (nonatomic,strong)void (^dongleStateCallBack)(BOOL success);
     return self;
 }
 
+-(NSMutableData *)voiceData{
+    if (_voiceData == nil) {
+        _voiceData = [[NSMutableData alloc] init];
+    }
+    return _voiceData;
+}
+
 
 - (AiRecordManager *)recordManager{
     if (!_recordManager) {
         _recordManager = [[AiRecordManager alloc] init];
         __weak typeof(self) ws = self;
         _recordManager.didRecordData = ^(NSData * _Nonnull data) {
-            [ws showLog:[NSString stringWithFormat:@"[audio]%@",data]];
             [ws sendRecordData:data];
         };
     }
 #pragma mark - other
 - (void)sendRecordData:(NSData *)data{
 //    [self showLog:[NSString stringWithFormat:@"[send][audio] %@",data]];
-    if (self.delegate)  [self.delegate tlwMouseSendRecordData:data];
+    
+//    if ([DeviceManger shared].appType == 2 || [DeviceManger shared].appType == 4) {
+        [self.voiceData appendData:data];
+        if (self.voiceData.length > 5000) {
+            if (self.delegate)  [self.delegate tlwMouseSendRecordData:self.voiceData];
+            self.voiceData = nil;
+        }
+//    }
+//    else{
+//        if (self.delegate)  [self.delegate tlwMouseSendRecordData:data];
+//    }    
 }
 
 - (void)sendCmdData:(NSData *)data{
index bb65899..1e7b9b1 100644 (file)
Binary files a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate and b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate differ
index af195d8..5f3d8f8 100644 (file)
@@ -24,7 +24,7 @@
     // Do any additional setup after loading the view.
     [self setupUI];
     [self setupDeviceManger];
-    [self getDeviceIinfo];
+   
 }
 
 - (void)loadView{
@@ -91,7 +91,8 @@
             if(connected){
                 ws.typeLabel.stringValue = connectType == 0 ?@"连接模式:蓝牙":@"连接模式:hid";
                 ws.connectLabel.stringValue = connected?@"连接状态:已连接":@"连接状态:未连接";
-                [ws geviceInfoAction];
+//                [ws geviceInfoAction];
+                [self getDeviceIinfo];
             }
             else{
                 ws.typeLabel.stringValue = @"连接模式:--";
 //        NSLog(@"开始录音");
     };
     manager.recordingCallBack = ^(NSString * _Nonnull data) {
-        //NSLog(@"%@",[NSString stringWithFormat:@"语音数据 = %@",data]);
+//        NSLog(@"%@",[NSString stringWithFormat:@"收到语音数据 = %@",data]);
     };
     manager.finishRecoredCallBack = ^(NSString * _Nonnull data) {
         //NSLog(@"%@",[NSString stringWithFormat:@"结束录音 = %@",data]);
     if ([DeviceManger shared].isConneted) {
         [self geviceInfoAction];
     }
-   //[self performSelector:@selector(getDeviceIinfo) withObject:nil afterDelay:10];
+   [self performSelector:@selector(getDeviceIinfo) withObject:nil afterDelay:1];
 }
 @end
index 30f1cdd..d2ea65a 100644 (file)
@@ -7,12 +7,12 @@
                <key>Masonry.xcscheme_^#shared#^_</key>
                <dict>
                        <key>orderHint</key>
-                       <integer>3</integer>
+                       <integer>4</integer>
                </dict>
                <key>Pods-MouseSdk.xcscheme_^#shared#^_</key>
                <dict>
                        <key>orderHint</key>
-                       <integer>4</integer>
+                       <integer>2</integer>
                </dict>
        </dict>
 </dict>