sdk里封装鉴权判断。假如设备还未鉴权,不允许使用SDK
authorliangzhenying <867174124@qq.com>
Tue, 19 Mar 2024 08:06:35 +0000 (16:06 +0800)
committerliangzhenying <867174124@qq.com>
Tue, 19 Mar 2024 08:06:35 +0000 (16:06 +0800)
17 files changed:
Document/AiMouseSdk接口文档.md
Document/MouseSDK数据交互流程-设备鉴权.eddx [new file with mode: 0644]
Document/MouseSdk连接流程.eddx
Document/数据交互流程.eddx
MouseSdk/AiMouseSdk/AiMouse.h
MouseSdk/AiMouseSdk/AiMouse.m
MouseSdk/AliIotConnectKitSDK/AliIotConnectKit/ThirdLib/IotRtc/libiotRtc.a
MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate
MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
MouseSdk/MouseSdk/BleManager.h
MouseSdk/MouseSdk/BleManager.m
MouseSdk/MouseSdk/ViewController.m
MouseSdk_Mac_V1.0.1/AiMouseSdk接口文档.pdf
MouseSdk_Mac_V1.0.1/MouseSdk数据交互流程.pdf [new file with mode: 0644]
MouseSdk_Mac_V1.0.1/MouseSdk连接流程.pdf [new file with mode: 0644]
MouseSdk_Mac_V1.0.1/数据交互流程.png [deleted file]
MouseSdk_Mac_V1.0.1/连接流程.png [deleted file]

index 5fb91b9..1313ca9 100644 (file)
@@ -4,10 +4,11 @@
 \r
 ## 文档修改记录\r
 \r
-| 版本  | 修改内容         | 修改人 | 修改时间   |\r
-| ----- | ---------------- | ------ | ---------- |\r
-| 1.0.0 | 初始版本         | 梁振营 | 2024-03-8  |\r
-| 1.0.1 | 鼠标按键指令修改 | 梁振营 | 2024-03-18 |\r
+| 版本  | 修改内容                                            | 修改人 | 修改时间   |\r
+| ----- | --------------------------------------------------- | ------ | ---------- |\r
+| 1.0.0 | 初始版本                                            | 梁振营 | 2024-03-8  |\r
+| 1.0.1 | 鼠标按键指令修改                                    | 梁振营 | 2024-03-18 |\r
+| 1.0.2 | 鉴权流程修改,只有鉴权成功了,SDK相关功能才可以使用 | 梁振营 | 2024-03-19 |\r
 \r
 \r
 \r
 \r
 \r
 \r
-## 蓝牙相关接口\r
+## SDK相关接口\r
 \r
 ```objective-c\r
+/// 单利\r
++(AiMouse *)shared;\r
+\r
 /// 开始鉴权\r
 - (void)startAuthentication;\r
 \r
 - (void)sendAiDataToSdk:(NSData *)data;\r
 ```\r
 \r
-## 蓝牙相关代理\r
+## SDK相关代理\r
 \r
 \r
 \r
 ```objective-c\r
 /// 鉴权状态回调\r
-/// - Parameter isSuccess:是否鉴权成功\r
-- (void)aiMouseAuthCallBack:(BOOL)isSuccess;\r
+/// - Parameter state:鉴权状态\r
+- (void)aiMouseAuthStateDidChange:(AiMouseAuthState)state;\r
 \r
-/// 鉴权数据回调,需要将此数据转发给蓝牙设备\r
+/// 鉴权数据回调,需要将此数据通过鉴权特征转发给蓝牙设备\r
 /// - Parameter data: 数据\r
 - (void)aiMouseSendAuthData:(NSData *)data;\r
 \r
           if ([characteristic.UUID.UUIDString isEqualToString:kAuthUUID]) {\r
               self.authCha = characteristic;\r
               [peripheral setNotifyValue:YES forCharacteristic:characteristic];\r
+              //开始鉴权\r
+              [[AiMouse shared] startAuthentication];\r
           }\r
           else if ([characteristic.UUID.UUIDString isEqualToString:kAiUUID]) {\r
               self.aiCha = characteristic;\r
 \r
   ```objective-c\r
   /// 鉴权状态回调\r
-  /// - Parameter isSuccess:是否鉴权成功\r
-  -(void)aiMouseAuthCallBack:(BOOL)isSuccess{\r
-      [self showLog:[NSString stringWithFormat:@"鉴权结果 = %@",@(isSuccess)]];\r
-      if(self.authCallBack){\r
-          self.authCallBack(isSuccess);\r
-      }\r
+  /// - Parameter state:鉴权状态\r
+  -(void)aiMouseAuthStateDidChange:(AiMouseAuthState)state{\r
+      [self showLog:[NSString stringWithFormat:@"鉴权结果 = %@",@(state)]];\r
   }\r
   /// 鉴权数据回调,需要将此数据转发给蓝牙设备\r
   /// - Parameter data: 数据\r
   - (void)aiMouseSendAuthData:(NSData *)data{\r
-      [self showLog:[NSString stringWithFormat:@"[send] %@",[AiTools dataToHexString:data]]];\r
       [self.connectPeripheral writeValue:data forCharacteristic:self.authCha type:CBCharacteristicWriteWithoutResponse];\r
   }\r
   /// 鼠标按键指令回调\r
   }\r
   ```\r
   \r
-- 判断鉴权\r
-\r
-  ```\r
-  [[AiMouse shared] startAuthentication];\r
-  ```\r
-  \r
-  鉴权回调\r
   \r
-  ```\r
-  /// - Parameter isSuccess:是否鉴权成功\r
-  \r
-  - (void)aiMouseAuthCallBack:(BOOL)isSuccess;\r
-  ```\r
-  \r
-  \r
-\r
-## 数据交互流程  \r
 \r
-鉴权特征数据走鉴权接口,AI特征数据走AI接口<img src="/Users/apple/Desktop/code/MouseSdk-iOS/Document/数据交互流程.png" alt="数据交互流程" style="zoom: 50%;" />\r
+  \r
 \r
+## 注意事项\r
 \r
+- 鉴权数据使用的是鉴权特征,走鉴权接口;AI数据使用的是AI特征,走AI接口。\r
+- 只有鉴权成功了以后,AI相关功能才可用。authState鉴权状态,默认是Unknow。所以必须在连上蓝牙设备找到鉴权特征后,需要主动调用startAuthentication方法去鉴权。(只有鉴权成功,AI键,语音键、M键才可用)\r
+- SDK只封装了蓝牙相关数据处理,APP自己维护蓝牙设备的扫描连接。蓝牙设备一段时间没有任何操作的话,会自动断开连接。APP可以在检测到断开后重连。\r
 \r
diff --git a/Document/MouseSDK数据交互流程-设备鉴权.eddx b/Document/MouseSDK数据交互流程-设备鉴权.eddx
new file mode 100644 (file)
index 0000000..6edc513
Binary files /dev/null and "b/Document/MouseSDK\346\225\260\346\215\256\344\272\244\344\272\222\346\265\201\347\250\213-\350\256\276\345\244\207\351\211\264\346\235\203.eddx" differ
index b43ef7c..2825627 100644 (file)
Binary files "a/Document/MouseSdk\350\277\236\346\216\245\346\265\201\347\250\213.eddx" and "b/Document/MouseSdk\350\277\236\346\216\245\346\265\201\347\250\213.eddx" differ
index dfe3d46..19f0f9e 100644 (file)
Binary files "a/Document/\346\225\260\346\215\256\344\272\244\344\272\222\346\265\201\347\250\213.eddx" and "b/Document/\346\225\260\346\215\256\344\272\244\344\272\222\346\265\201\347\250\213.eddx" differ
index 1871b65..49d6cdf 100644 (file)
@@ -9,13 +9,19 @@
 
 NS_ASSUME_NONNULL_BEGIN
 
+typedef NS_ENUM(NSInteger,AiMouseAuthState) {
+    AiMouseAuthState_Unknow = 0,///未知
+    AiMouseAuthState_Success,///鉴权成功
+    AiMouseAuthState_Failure///鉴权失败
+};
+
 @protocol AiMouseDelegate <NSObject>
 
 /// 鉴权状态回调
-/// - Parameter isSuccess:是否鉴权成功
-- (void)aiMouseAuthCallBack:(BOOL)isSuccess;
+/// - Parameter state:鉴权状态
+- (void)aiMouseAuthStateDidChange:(AiMouseAuthState)state;
 
-/// 鉴权数据回调,需要将此数据转发给蓝牙设备
+/// 鉴权数据回调,需要将此数据通过鉴权特征转发给蓝牙设备
 /// - Parameter data: 数据
 - (void)aiMouseSendAuthData:(NSData *)data;
 
@@ -32,6 +38,7 @@ NS_ASSUME_NONNULL_BEGIN
 @interface AiMouse : NSObject
 @property (nonatomic, readonly) NSString *version;/// 版本号
 @property (nonatomic, weak) id<AiMouseDelegate> delegate;/// 代理
+@property (nonatomic, readonly) AiMouseAuthState authState;/// 鉴权状态,默认是Unknow。所以必须在连上蓝牙设备找到鉴权特征后,需要主动调用startAuthentication方法去鉴权。(只有鉴权成功,AI键,语音键、M键才可用)
 
 /// 单利
 +(AiMouse *)shared;
index 046e57c..0c08a72 100644 (file)
     return manager;
 }
 
+-(instancetype)init{
+    if (self = [super init]) {
+        _authState = AiMouseAuthState_Unknow;
+    }
+    return self;
+}
+
 -(NSString *)version{
     return @"1.0.1";
 }
@@ -52,9 +59,7 @@
             [ws sendAuthData:data];
         };
         _authManager.authCallBack = ^(BOOL isSuccess) {
-            if (ws.delegate) {
-                [ws.delegate aiMouseAuthCallBack:isSuccess];
-            }
+            [ws authResult:isSuccess];
         };
     }
     return _authManager;
@@ -78,6 +83,7 @@
 }
 //开始鉴权
 - (void)startAuthentication{
+    _authState = AiMouseAuthState_Unknow;
     [self.authManager login];
 }
 
 }
 
 - (void)sendRecordData:(NSData *)data{
+    if (self.authState != AiMouseAuthState_Success) return;
     if (self.delegate) {
         [self.delegate aiMouseSendRecordData:data];
     }
 }
 - (void)sendCmdData:(NSData *)data{
+    if (self.authState != AiMouseAuthState_Success) return;
     if (self.delegate) {
         [self.delegate aiMouseSendCmdData:data];
     }
 }
+
+- (void)authResult:(BOOL)isSuccess{
+    _authState = isSuccess ? AiMouseAuthState_Success:AiMouseAuthState_Failure;
+    if (self.delegate) {
+        [self.delegate aiMouseAuthStateDidChange:self.authState];
+    }
+}
 - (void)showLog:(NSString *)log{
 //    NSLog(@"[sdk]%@",log);
 }
index f23e4e8..4570a5c 100644 (file)
Binary files a/MouseSdk/AliIotConnectKitSDK/AliIotConnectKit/ThirdLib/IotRtc/libiotRtc.a and b/MouseSdk/AliIotConnectKitSDK/AliIotConnectKit/ThirdLib/IotRtc/libiotRtc.a differ
index 6f27b06..8c43101 100644 (file)
Binary files a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate and b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate differ
index a37bea2..072f2d0 100644 (file)
             endingLineNumber = "210"
             landmarkName = "writeDeviceInfoToBle(deviceSecret:)"
             landmarkType = "7">
+            <Locations>
+               <Location
+                  uuid = "8655E077-F140-41E8-B58D-330D15C6F07A - 25935f69e77a4b93"
+                  shouldBeEnabled = "Yes"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "AliIotConnectKit.FGSCheckService_C.writeDeviceInfoToBle(deviceSecret: Swift.String) -&gt; ()"
+                  moduleName = "AliIotConnectKit"
+                  usesParentBreakpointCondition = "Yes"
+                  urlString = "file:///Users/apple/Desktop/code/MouseSdk-iOS/MouseSdk/AliIotConnectKitSDK/AliIotConnectKit/Service/FGSCheckService_C.swift"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "211"
+                  endingLineNumber = "211"
+                  offsetFromSymbolStart = "2398">
+               </Location>
+               <Location
+                  uuid = "8655E077-F140-41E8-B58D-330D15C6F07A - 25935f69e77a4b93"
+                  shouldBeEnabled = "Yes"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "AliIotConnectKit.FGSCheckService_C.writeDeviceInfoToBle(deviceSecret: Swift.String) -&gt; ()"
+                  moduleName = "AliIotConnectKit"
+                  usesParentBreakpointCondition = "Yes"
+                  urlString = "file:///Users/apple/Desktop/code/MouseSdk-iOS/MouseSdk/AliIotConnectKitSDK/AliIotConnectKit/Service/FGSCheckService_C.swift"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "211"
+                  endingLineNumber = "211"
+                  offsetFromSymbolStart = "2092">
+               </Location>
+               <Location
+                  uuid = "8655E077-F140-41E8-B58D-330D15C6F07A - 25935f69e77a4bb2"
+                  shouldBeEnabled = "Yes"
+                  ignoreCount = "0"
+                  continueAfterRunningActions = "No"
+                  symbolName = "AliIotConnectKit.FGSCheckService_C.writeDeviceInfoToBle(deviceSecret: Swift.String) -&gt; ()"
+                  moduleName = "AliIotConnectKit"
+                  usesParentBreakpointCondition = "Yes"
+                  urlString = "file:///Users/apple/Desktop/code/MouseSdk-iOS/MouseSdk/AliIotConnectKitSDK/AliIotConnectKit/Service/FGSCheckService_C.swift"
+                  startingColumnNumber = "9223372036854775807"
+                  endingColumnNumber = "9223372036854775807"
+                  startingLineNumber = "210"
+                  endingLineNumber = "210"
+                  offsetFromSymbolStart = "2092">
+               </Location>
+            </Locations>
          </BreakpointContent>
       </BreakpointProxy>
    </Breakpoints>
index 6e3749e..3967af4 100644 (file)
@@ -30,8 +30,6 @@ NS_ASSUME_NONNULL_BEGIN
 /// - Parameter peripheral: 蓝牙设备
 - (void)connectPeripheral:(CBPeripheral *)peripheral;
 
-/// 开始鉴权
-- (void)startAuthentication;
 @end
 
 NS_ASSUME_NONNULL_END
index 68c64bb..7238ff9 100644 (file)
         if ([characteristic.UUID.UUIDString isEqualToString:kAuthUUID]) {
             self.authCha = characteristic;
             [peripheral setNotifyValue:YES forCharacteristic:characteristic];
+            //开始鉴权
+            [[AiMouse shared] startAuthentication];
         }
         else if ([characteristic.UUID.UUIDString isEqualToString:kAiUUID]) {
             self.aiCha = characteristic;
 
 #pragma mark - AiDelegate
 /// 鉴权状态回调
-/// - Parameter isSuccess:是否鉴权成功
--(void)aiMouseAuthCallBack:(BOOL)isSuccess{
-    [self showLog:[NSString stringWithFormat:@"鉴权结果 = %@",@(isSuccess)]];
+/// - Parameter state:鉴权状态
+-(void)aiMouseAuthStateDidChange:(AiMouseAuthState)state{
+    [self showLog:[NSString stringWithFormat:@"鉴权结果 = %@",@(state)]];
     if(self.authCallBack){
-        self.authCallBack(isSuccess);
+        self.authCallBack(state == AiMouseAuthState_Success);
     }
 }
 /// 鉴权数据回调,需要将此数据转发给蓝牙设备
 #pragma mark - public
 /// 连接设备
 - (void)startScanDevice{
-    NSLog(@"banben***** = %@",[[AiMouse shared] version]);
     [self.centralManager scanForPeripheralsWithServices:nil options:@{CBCentralManagerScanOptionAllowDuplicatesKey : [NSNumber numberWithBool:NO]}];
 }
 
     [self.centralManager connectPeripheral:peripheral options:@{CBConnectPeripheralOptionNotifyOnConnectionKey : [NSNumber numberWithBool:YES]}];
 }
 
-/// 开始鉴权
-- (void)startAuthentication{
-    [[AiMouse shared] startAuthentication];
-}
-
 #pragma mark - other
 //自动连接,获取已配对的蓝牙,取第一个连接
 - (void)autoConnectDevice{
         return;
     }
     NSArray<CBPeripheral *> *devices = [self.centralManager retrieveConnectedPeripheralsWithServices:@[[CBUUID UUIDWithString:kServiceUUID]]];
-    for (CBPeripheral *peripheral in devices) {
+    if (devices.count > 0) {
+        CBPeripheral *peripheral = devices[0];
         [self showLog:[NSString stringWithFormat:@"匹配过的设备%@",peripheral.name]];
         [self connectPeripheral:peripheral];
-        break;
     }
     // 10s自动重连
     [self performSelector:@selector(autoConnectDevice) withObject:nil afterDelay:10];
index 06e4dd9..58c0008 100644 (file)
@@ -37,7 +37,7 @@
     self.title = @"AI SDK";
 
     {
-        NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(100, self.view.bounds.size.height - 120, 100, 45)];
+        NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(100, self.view.bounds.size.height - 160, 100, 45)];
         btn.bordered = true;
         btn.title = @"扫描";
         [btn setTarget:self];
         btn.state = 1;
         [self.view addSubview:btn];
     }
-    {
-        NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(100, self.view.bounds.size.height - 200, 100, 45)];
-        btn.bordered = true;
-        btn.title = @"鉴权";
-        [btn setTarget:self];
-        [btn setAction:@selector(checkAuth)];
-        btn.state = 1;
-        [self.view addSubview:btn];
-    }
     {
         NSTextField *label = [[NSTextField alloc] initWithFrame:CGRectMake(230, self.view.bounds.size.height - 120, 200, 35)];
         label.editable = NO;
@@ -67,7 +58,7 @@
         NSTextField *label = [[NSTextField alloc] initWithFrame:CGRectMake(230, self.view.bounds.size.height - 200, 200, 35)];
         label.editable = NO;
         label.bordered = NO;
-        label.stringValue = @"鉴权状态:--";
+        label.stringValue = @"鉴权状态:unknow";
         label.backgroundColor = NSColor.clearColor;
         self.autoLabel = label;
         [self.view addSubview:label];
 }
 
 - (void)checkAuth{
-    [[BleManager shared] startAuthentication];
+//    [[BleManager shared] startAuthentication];
 }
 
 - (void)showAuthResult:(BOOL)isSuccess{
     dispatch_async(dispatch_get_main_queue(), ^{
-        self.autoLabel.stringValue = isSuccess?@"鉴权结果:鉴权成功":@"鉴权结果:鉴权失败";
-//        NSAlert *alert = [NSAlert new];
-//         [alert addButtonWithTitle:@"确定"];
-//         [alert setMessageText:isSuccess?@"鉴权成功":@"鉴权失败"];
-//         [alert setAlertStyle:NSAlertStyleInformational];
-//         [alert beginSheetModalForWindow:[self.view window] completionHandler:^(NSModalResponse returnCode) {
-//         }];
+        self.autoLabel.stringValue = isSuccess?@"鉴权状态:鉴权成功":@"鉴权状态:鉴权失败";
     });
 }
 
index d0fea61..1617375 100644 (file)
Binary files "a/MouseSdk_Mac_V1.0.1/AiMouseSdk\346\216\245\345\217\243\346\226\207\346\241\243.pdf" and "b/MouseSdk_Mac_V1.0.1/AiMouseSdk\346\216\245\345\217\243\346\226\207\346\241\243.pdf" differ
diff --git a/MouseSdk_Mac_V1.0.1/MouseSdk数据交互流程.pdf b/MouseSdk_Mac_V1.0.1/MouseSdk数据交互流程.pdf
new file mode 100644 (file)
index 0000000..9251b02
Binary files /dev/null and "b/MouseSdk_Mac_V1.0.1/MouseSdk\346\225\260\346\215\256\344\272\244\344\272\222\346\265\201\347\250\213.pdf" differ
diff --git a/MouseSdk_Mac_V1.0.1/MouseSdk连接流程.pdf b/MouseSdk_Mac_V1.0.1/MouseSdk连接流程.pdf
new file mode 100644 (file)
index 0000000..7fdbc4f
Binary files /dev/null and "b/MouseSdk_Mac_V1.0.1/MouseSdk\350\277\236\346\216\245\346\265\201\347\250\213.pdf" differ
diff --git a/MouseSdk_Mac_V1.0.1/数据交互流程.png b/MouseSdk_Mac_V1.0.1/数据交互流程.png
deleted file mode 100644 (file)
index ba4b941..0000000
Binary files "a/MouseSdk_Mac_V1.0.1/\346\225\260\346\215\256\344\272\244\344\272\222\346\265\201\347\250\213.png" and /dev/null differ
diff --git a/MouseSdk_Mac_V1.0.1/连接流程.png b/MouseSdk_Mac_V1.0.1/连接流程.png
deleted file mode 100644 (file)
index 0020ae6..0000000
Binary files "a/MouseSdk_Mac_V1.0.1/\350\277\236\346\216\245\346\265\201\347\250\213.png" and /dev/null differ