From: liangzhenying <867174124@qq.com> Date: Wed, 5 Jun 2024 06:35:57 +0000 (+0800) Subject: 鉴权实际改成只要收到数据,没有鉴权成功的,都会去请求鉴权 X-Git-Tag: 千寻适配d9~59 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=5b471fe9015571ef85d85b15e9c88cb05dac5f2c;p=mirrors%2FMouseSdk-MacOS.git 鉴权实际改成只要收到数据,没有鉴权成功的,都会去请求鉴权 --- diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.h b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.h index e3b8f07..ce5bbd0 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.h +++ b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.h @@ -88,6 +88,10 @@ typedef NS_ENUM(NSInteger,AiMouseAuthState) { /// - Parameter level: 等级 - (void)setLogLevel:(AiMouseLogLevel)level; + +/// 断开连接 +- (void)didDisconnect; + /// 切换连接类型 /// - Parameter type: 连接类型 - (void)switchConnect:(AiMouseConnectType)type; diff --git a/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m index a501d16..1785a8a 100644 --- a/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m +++ b/MouseSdk/AiMouseSdk/AiMouseSdk/AiMouseSdk.m @@ -39,7 +39,7 @@ @property (nonatomic, strong) NSString *updateDeviceSecret;//更新的deviceSecret @property (nonatomic, strong) AiConnectManager *connectManager; - +@property (nonatomic, assign) BOOL isAuthing; @end @implementation AiMouse @@ -64,7 +64,7 @@ } -(NSString *)version{ - return @"1.0.23"; + return @"1.0.27"; } -(AiDeviceInfoManager *)deviceInfoManager{ @@ -138,6 +138,10 @@ - (void)setLogLevel:(AiMouseLogLevel)level{ _logLevel = level; } +- (void)didDisconnect{ + [self showLog:@"系统断开连接"]; + [self.connectManager disConnected]; +} - (void)switchConnect:(AiMouseConnectType)type{ if(type != _connectType && self.connected){ [self.connectManager disConnected]; @@ -154,18 +158,14 @@ - (void)startAuthentication:(void (^)(AiMouseAuthState))complete{ // [self showLog:@"获取设备信息"]; // _authState = AiMouseAuthState_Unknow; + [self showLog:@"开始鉴权"]; self.authBlock = complete; __block typeof(self) ws = self; [self getDeviceInfo:^(AiMouseDeviceInfo *deviceInfo, NSError *error) { if (error ) { - if(ws.authBlock == AiMouseAuthState_Unknow){ - [ws showLog:@"鉴权失败"]; - ws.authBlock(AiMouseAuthState_Failure); - - } + ws.authBlock(AiMouseAuthState_Failure); } else{ - [ws showLog:@"开始鉴权"]; [ws.authManager loginWith:deviceInfo]; } }]; @@ -175,6 +175,11 @@ [self.connectManager resetTimeOut]; [self showLog:[NSString stringWithFormat:@"[receive][Ai] %@",data]]; + + if (self.authState != AiMouseAuthState_Success){ + [self showLog:@"设备还未鉴权!!!"]; + return; + } if(self.connectType == AiMouseConnectType_hid){ // 0AFFFF12BC32 if(data.length == 6){ @@ -217,6 +222,7 @@ [self.connectManager resetTimeOut]; [self showLog:[NSString stringWithFormat:@"[receive][device] %@",data]]; [self.deviceInfoManager receiveData:data]; + [self checkAuthState]; } - (void)setDeviceSecret:(NSString *)value completation:(AiCmdFinishBlock)complete{ self.updateDeviceSecret = value; @@ -319,25 +325,24 @@ } #pragma mark - other - (void)sendRecordData:(NSData *)data{ - if (self.authState != AiMouseAuthState_Success){ - [self showLog:@"设备还未鉴权!!!"]; - return; - }; +// if (self.authState != AiMouseAuthState_Success){ +// [self showLog:@"设备还未鉴权!!!"]; +// return; +// }; [self showLog:[NSString stringWithFormat:@"[audio] %@",data]]; if (self.delegate) [self.delegate aiMouseSendRecordData:data]; } - (void)sendCmdData:(NSData *)data{ - if (self.authState != AiMouseAuthState_Success){ - [self showLog:@"设备还未鉴权!!!"]; - return; - } +// if (self.authState != AiMouseAuthState_Success){ +// [self showLog:@"设备还未鉴权!!!"]; +// return; +// } [self showLog:[NSString stringWithFormat:@"[send] %@",data]]; if (self.delegate) [self.delegate aiMouseSendCmdData:data]; } - (void)authResult:(BOOL)isSuccess{ _authState = isSuccess ? AiMouseAuthState_Success:AiMouseAuthState_Failure; - [self showLog:isSuccess?@"鉴权成功":@"鉴权失败"]; [self.deviceInfoManager setAuthStateToDevice:isSuccess]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ @@ -353,6 +358,20 @@ } } +- (void)checkAuthState{ + if (self.authState != AiMouseAuthState_Success) { + if (self.isAuthing) { + return; + } + self.isAuthing = true; + __weak typeof(self) ws = self; + [self startAuthentication:^(AiMouseAuthState state) { + ws.isAuthing = false; + [ws showLog:state == AiMouseAuthState_Success? @"鉴权成功":@"鉴权失败"]; + if(ws.delegate) [ws.delegate aiMouseAuthenticationResult:state]; + }]; + } +} #pragma mark - deviceInfo - (void)startRecord{ // [self showLog:@"开始录音"]; @@ -366,18 +385,14 @@ #pragma mark - AiConnectManagerDelegate -(void)aiConnectManager:(AiConnectManager *)manager connectStateDidChange:(BOOL)connected{ + if (connected == false) { + _authState = AiMouseAuthState_Unknow; + } _connected = connected; if([self.delegate respondsToSelector:@selector(aiMouseConnectStateDidChange:)]) [self.delegate aiMouseConnectStateDidChange:connected]; // [self showLog:[NSString stringWithFormat:@"状态改变 = %@",@(connected)]]; - if (connected) { - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - __weak typeof(self) ws = self; - [self startAuthentication:^(AiMouseAuthState state) { - if(ws.delegate) [ws.delegate aiMouseAuthenticationResult:state]; - }]; - }); - } +// [self checkAuthState]; } -(void)aiConnectManagerReSendData:(AiConnectManager *)manager{ __weak typeof(self) ws = self; diff --git a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate index b45de7d..22813d7 100644 Binary files a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate and b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/MouseSdk/MouseSdk/BleManager.m b/MouseSdk/MouseSdk/BleManager.m index a728600..d63c66e 100644 --- a/MouseSdk/MouseSdk/BleManager.m +++ b/MouseSdk/MouseSdk/BleManager.m @@ -90,7 +90,8 @@ if(self.didDisConnectDevice){ self.didDisConnectDevice(peripheral); } -// [self autoConnectDevice]; +// [self aiMouseConnectStateDidChange:false]; + [[AiMouse shared] didDisconnect]; } - (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(nullable NSError *)error{ [self showLog:[NSString stringWithFormat:@"连接失败。。。%@",error.description]]; diff --git a/MouseSdk/MouseSdk/HidManager.m b/MouseSdk/MouseSdk/HidManager.m index 2913e42..80f344f 100644 --- a/MouseSdk/MouseSdk/HidManager.m +++ b/MouseSdk/MouseSdk/HidManager.m @@ -108,7 +108,7 @@ static void hidDisAppearDevice(void *inContext,IOReturn inResult,void *inSender, uint32_t PrimaryUsage = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsageKey)); if(PrimaryUsagePage == 1 && PrimaryUsage == 0){ - [HidManager shared].connectStateCallBack(false); + [[AiMouse shared] didDisconnect]; } } @@ -135,7 +135,10 @@ static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDRe /// 设备信息数据回调,需要将此数据通过设备信息特征转发给蓝牙设备 /// - Parameter data: 数据 -(void)aiMouseSendDeviceInfoData:(NSData *)data{ - [self sendData:data toDevice:self.deviceInfoCha]; + if([AiMouse shared].connected){ + [self sendData:data toDevice:self.deviceInfoCha]; + } + } /// 设备鉴权结果返回