From: liangzhenying <867174124@qq.com> Date: Fri, 30 May 2025 08:34:40 +0000 (+0800) Subject: 修复频繁获取设备信息失败bug X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=c67d8774d722c103ef9a736d33571666fa21ccf9;p=mirrors%2FMouseSdk-MacOS.git 修复频繁获取设备信息失败bug --- diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist b/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist index 64bd978..6349347 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/MouseSdk/AiMouseSdk/AiMouseSdk.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,7 +7,7 @@ AiMouseSdk copy.xcscheme_^#shared#^_ orderHint - 2 + 3 AiMouseSdk.xcscheme_^#shared#^_ diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.h b/MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.h index 2351512..4a562cb 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.h +++ b/MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.h @@ -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); diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.m b/MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.m index 3b7f186..d4942d7 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.m +++ b/MouseSdk/AiMouseSdk/AiMouseSdk/AiDeviceInfoManager.m @@ -31,7 +31,7 @@ @interface AiDeviceInfoManager() @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); diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m index 1df5a3f..1adf0b8 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m +++ b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m @@ -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; @@ -60,12 +62,18 @@ -(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) { @@ -237,6 +245,15 @@ } - (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)) { @@ -244,6 +261,7 @@ deviceInfo.byteAuthInfo = info; [ws showLog:deviceInfo.description]; complete(deviceInfo,error); + self.isLoading = false; }]; } else{ @@ -331,16 +349,16 @@ #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]]; @@ -357,7 +375,6 @@ - (void)startRecord{ // [self showLog:@"开始录音"]; [self.recordManager start]; - self.voiceData = [[NSMutableData alloc] init]; } - (void)stopRecord:(BOOL)sendCmd{ diff --git a/MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.m b/MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.m index fff141c..cb0ec49 100644 --- a/MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.m +++ b/MouseSdk/AiMouseSdk/ByteDance/ByteDanceSdk.m @@ -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{ diff --git a/MouseSdk/AiMouseSdk/M8/M8MouseSdk.m b/MouseSdk/AiMouseSdk/M8/M8MouseSdk.m index 183256d..7d75eb1 100644 --- a/MouseSdk/AiMouseSdk/M8/M8MouseSdk.m +++ b/MouseSdk/AiMouseSdk/M8/M8MouseSdk.m @@ -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模式"]; @@ -170,15 +171,15 @@ } #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]; } @@ -275,8 +276,16 @@ } #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{ @@ -304,6 +313,7 @@ } #pragma mark - deviceInfo - (void)startRecord{ + self.voiceData = [[NSMutableData alloc] init]; [self.recordManager start]; } diff --git a/MouseSdk/AiMouseSdk/Manager/DeviceManger.m b/MouseSdk/AiMouseSdk/Manager/DeviceManger.m index a3058f5..989b41c 100644 --- a/MouseSdk/AiMouseSdk/Manager/DeviceManger.m +++ b/MouseSdk/AiMouseSdk/Manager/DeviceManger.m @@ -53,7 +53,7 @@ - (instancetype)init{ self = [super init]; if (self) { - self.version = @"MouseSdk_v2025052701"; + self.version = @"MouseSdk_v2025052901"; } return self; } @@ -1042,7 +1042,6 @@ //@"08":@"08", /// 其他未定义 - (void)m8MouseSendCmdData:(NSData *)data{ - NSLog(@"%@",data); uint8 cmd; [data getBytes:&cmd length:1]; if( cmd == 0x01){ @@ -1161,6 +1160,7 @@ - (void)sendRecordingCallBackToApp:(NSData *)data{ [self.recordData appendData:data]; if (self.recordingCallBack) { + [self showLog:@"超过5000B,发送给app"]; // 将NSData转换为Base64编码的字符串 self.recordingCallBack( [data base64EncodedStringWithOptions:0]); } diff --git a/MouseSdk/AiMouseSdk/Manager/LogManager.h b/MouseSdk/AiMouseSdk/Manager/LogManager.h index 440eeb3..e07cf95 100644 --- a/MouseSdk/AiMouseSdk/Manager/LogManager.h +++ b/MouseSdk/AiMouseSdk/Manager/LogManager.h @@ -22,7 +22,5 @@ - (void)saveLog:(NSString *)log; -- (NSString *)getLogs; - @end diff --git a/MouseSdk/AiMouseSdk/Manager/LogManager.m b/MouseSdk/AiMouseSdk/Manager/LogManager.m index 0ba90fa..091d570 100644 --- a/MouseSdk/AiMouseSdk/Manager/LogManager.m +++ b/MouseSdk/AiMouseSdk/Manager/LogManager.m @@ -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; @@ -120,15 +118,6 @@ } - (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 diff --git a/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m b/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m index cb1b4f1..b2dc1e6 100644 --- a/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m +++ b/MouseSdk/AiMouseSdk/TlwMouseSdk/TlwMouseSdk.m @@ -25,7 +25,7 @@ @end @interface TlwMouse() - +@property (nonatomic, strong) NSMutableData *voiceData; @property (nonatomic, strong) AiRecordManager *recordManager; @property (nonatomic,strong)void (^dongleStateCallBack)(BOOL success); @@ -57,13 +57,19 @@ 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]; }; } @@ -726,7 +732,17 @@ #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{ diff --git a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate index bb65899..1e7b9b1 100644 Binary files a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate and b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/MouseSdk/MouseSdk/ViewController.m b/MouseSdk/MouseSdk/ViewController.m index af195d8..5f3d8f8 100644 --- a/MouseSdk/MouseSdk/ViewController.m +++ b/MouseSdk/MouseSdk/ViewController.m @@ -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 = @"连接模式:--"; @@ -105,7 +106,7 @@ // NSLog(@"开始录音"); }; manager.recordingCallBack = ^(NSString * _Nonnull data) { - //NSLog(@"%@",[NSString stringWithFormat:@"语音数据 = %@",data]); +// NSLog(@"%@",[NSString stringWithFormat:@"收到语音数据 = %@",data]); }; manager.finishRecoredCallBack = ^(NSString * _Nonnull data) { //NSLog(@"%@",[NSString stringWithFormat:@"结束录音 = %@",data]); @@ -204,6 +205,6 @@ if ([DeviceManger shared].isConneted) { [self geviceInfoAction]; } - //[self performSelector:@selector(getDeviceIinfo) withObject:nil afterDelay:10]; + [self performSelector:@selector(getDeviceIinfo) withObject:nil afterDelay:1]; } @end diff --git a/MouseSdk/Pods/Pods.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist b/MouseSdk/Pods/Pods.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist index 30f1cdd..d2ea65a 100644 --- a/MouseSdk/Pods/Pods.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/MouseSdk/Pods/Pods.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,12 +7,12 @@ Masonry.xcscheme_^#shared#^_ orderHint - 3 + 4 Pods-MouseSdk.xcscheme_^#shared#^_ orderHint - 4 + 2