From: liangzhenying <867174124@qq.com>
Date: Tue, 19 Mar 2024 08:06:35 +0000 (+0800)
Subject: sdk里封装鉴权判断。假如设备还未鉴权,不允许使用SDK
X-Git-Tag: é¿éé´æ~13
X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=bc03c4bab137a671ff6a06c85fd34afc02e375f7;p=mirrors%2FMouseSdk-MacOS.git
sdk里封装鉴权判断。假如设备还未鉴权,不允许使用SDK
---
diff --git "a/Document/AiMouseSdk\346\216\245\345\217\243\346\226\207\346\241\243.md" "b/Document/AiMouseSdk\346\216\245\345\217\243\346\226\207\346\241\243.md"
index 5fb91b9..1313ca9 100644
--- "a/Document/AiMouseSdk\346\216\245\345\217\243\346\226\207\346\241\243.md"
+++ "b/Document/AiMouseSdk\346\216\245\345\217\243\346\226\207\346\241\243.md"
@@ -4,10 +4,11 @@
## ææ¡£ä¿®æ¹è®°å½
-| çæ¬ | ä¿®æ¹å
容 | ä¿®æ¹äºº | ä¿®æ¹æ¶é´ |
-| ----- | ---------------- | ------ | ---------- |
-| 1.0.0 | åå§çæ¬ | æ¢æ¯è¥ | 2024-03-8 |
-| 1.0.1 | é¼ æ æé®æä»¤ä¿®æ¹ | æ¢æ¯è¥ | 2024-03-18 |
+| çæ¬ | ä¿®æ¹å
容 | ä¿®æ¹äºº | ä¿®æ¹æ¶é´ |
+| ----- | --------------------------------------------------- | ------ | ---------- |
+| 1.0.0 | åå§çæ¬ | æ¢æ¯è¥ | 2024-03-8 |
+| 1.0.1 | é¼ æ æé®æä»¤ä¿®æ¹ | æ¢æ¯è¥ | 2024-03-18 |
+| 1.0.2 | é´ææµç¨ä¿®æ¹ï¼åªæé´ææåäºï¼SDKç¸å
³åè½æå¯ä»¥ä½¿ç¨ | æ¢æ¯è¥ | 2024-03-19 |
@@ -31,9 +32,12 @@
-## èçç¸å
³æ¥å£
+## SDKç¸å
³æ¥å£
```objective-c
+/// åå©
++(AiMouse *)shared;
+
/// å¼å§é´æ
- (void)startAuthentication;
@@ -46,16 +50,16 @@
- (void)sendAiDataToSdk:(NSData *)data;
```
-## èçç¸å
³ä»£ç
+## SDKç¸å
³ä»£ç
```objective-c
/// é´æç¶æåè°
-/// - Parameter isSuccess:æ¯å¦é´ææå
-- (void)aiMouseAuthCallBack:(BOOL)isSuccess;
+/// - Parameter state:é´æç¶æ
+- (void)aiMouseAuthStateDidChange:(AiMouseAuthState)state;
-/// é´ææ°æ®åè°ï¼éè¦å°æ¤æ°æ®è½¬åç»èç设å¤
+/// é´ææ°æ®åè°ï¼éè¦å°æ¤æ°æ®éè¿é´æç¹å¾è½¬åç»èç设å¤
/// - Parameter data: æ°æ®
- (void)aiMouseSendAuthData:(NSData *)data;
@@ -99,6 +103,8 @@
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;
@@ -132,17 +138,13 @@
```objective-c
/// é´æç¶æåè°
- /// - Parameter isSuccess:æ¯å¦é´ææå
- -(void)aiMouseAuthCallBack:(BOOL)isSuccess{
- [self showLog:[NSString stringWithFormat:@"é´æç»æ = %@",@(isSuccess)]];
- if(self.authCallBack){
- self.authCallBack(isSuccess);
- }
+ /// - Parameter state:é´æç¶æ
+ -(void)aiMouseAuthStateDidChange:(AiMouseAuthState)state{
+ [self showLog:[NSString stringWithFormat:@"é´æç»æ = %@",@(state)]];
}
/// é´ææ°æ®åè°ï¼éè¦å°æ¤æ°æ®è½¬åç»èç设å¤
/// - Parameter data: æ°æ®
- (void)aiMouseSendAuthData:(NSData *)data{
- [self showLog:[NSString stringWithFormat:@"[send] %@",[AiTools dataToHexString:data]]];
[self.connectPeripheral writeValue:data forCharacteristic:self.authCha type:CBCharacteristicWriteWithoutResponse];
}
/// é¼ æ æé®æä»¤åè°
@@ -176,25 +178,13 @@
}
```
-- 夿鴿
-
- ```
- [[AiMouse shared] startAuthentication];
- ```
-
- é´æåè°
- ```
- /// - Parameter isSuccess:æ¯å¦é´ææå
-
- - (void)aiMouseAuthCallBack:(BOOL)isSuccess;
- ```
-
-
-
-## æ°æ®äº¤äºæµç¨
-é´æç¹å¾æ°æ®èµ°é´ææ¥å£ï¼AIç¹å¾æ°æ®èµ°AIæ¥å£
+
+## 注æäºé¡¹
+- é´ææ°æ®ä½¿ç¨çæ¯é´æç¹å¾ï¼èµ°é´ææ¥å£ï¼AIæ°æ®ä½¿ç¨çæ¯AIç¹å¾ï¼èµ°AIæ¥å£ã
+- åªæé´ææåäºä»¥åï¼AIç¸å
³åè½æå¯ç¨ãauthStateé´æç¶æ,é»è®¤æ¯Unknowãæä»¥å¿
é¡»å¨è¿ä¸èçè®¾å¤æ¾å°é´æç¹å¾åï¼éè¦ä¸»å¨è°ç¨startAuthenticationæ¹æ³å»é´æãï¼åªæé´ææåï¼AIé®ï¼è¯é³é®ãM鮿å¯ç¨ï¼
+- SDKåªå°è£
äºèçç¸å
³æ°æ®å¤çï¼APPèªå·±ç»´æ¤èç设å¤çæ«æè¿æ¥ãèç设å¤ä¸æ®µæ¶é´æ²¡æä»»ä½æä½çè¯ï¼ä¼èªå¨æå¼è¿æ¥ãAPPå¯ä»¥å¨æ£æµå°æå¼åéè¿ã
diff --git "a/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" "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"
new file mode 100644
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
diff --git "a/Document/MouseSdk\350\277\236\346\216\245\346\265\201\347\250\213.eddx" "b/Document/MouseSdk\350\277\236\346\216\245\346\265\201\347\250\213.eddx"
index b43ef7c..2825627 100644
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
diff --git "a/Document/\346\225\260\346\215\256\344\272\244\344\272\222\346\265\201\347\250\213.eddx" "b/Document/\346\225\260\346\215\256\344\272\244\344\272\222\346\265\201\347\250\213.eddx"
index dfe3d46..19f0f9e 100644
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
diff --git a/MouseSdk/AiMouseSdk/AiMouse.h b/MouseSdk/AiMouseSdk/AiMouse.h
index 1871b65..49d6cdf 100644
--- a/MouseSdk/AiMouseSdk/AiMouse.h
+++ b/MouseSdk/AiMouseSdk/AiMouse.h
@@ -9,13 +9,19 @@
NS_ASSUME_NONNULL_BEGIN
+typedef NS_ENUM(NSInteger,AiMouseAuthState) {
+ AiMouseAuthState_Unknow = 0,///æªç¥
+ AiMouseAuthState_Success,///é´ææå
+ AiMouseAuthState_Failure///é´æå¤±è´¥
+};
+
@protocol AiMouseDelegate
/// é´æç¶æåè°
-/// - 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 delegate;/// 代ç
+@property (nonatomic, readonly) AiMouseAuthState authState;/// é´æç¶æ,é»è®¤æ¯Unknowãæä»¥å¿
é¡»å¨è¿ä¸èçè®¾å¤æ¾å°é´æç¹å¾åï¼éè¦ä¸»å¨è°ç¨startAuthenticationæ¹æ³å»é´æãï¼åªæé´ææåï¼AIé®ï¼è¯é³é®ãM鮿å¯ç¨ï¼
/// åå©
+(AiMouse *)shared;
diff --git a/MouseSdk/AiMouseSdk/AiMouse.m b/MouseSdk/AiMouseSdk/AiMouse.m
index 046e57c..0c08a72 100644
--- a/MouseSdk/AiMouseSdk/AiMouse.m
+++ b/MouseSdk/AiMouseSdk/AiMouse.m
@@ -27,6 +27,13 @@
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];
}
@@ -111,15 +117,24 @@
}
- (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);
}
diff --git a/MouseSdk/AliIotConnectKitSDK/AliIotConnectKit/ThirdLib/IotRtc/libiotRtc.a b/MouseSdk/AliIotConnectKitSDK/AliIotConnectKit/ThirdLib/IotRtc/libiotRtc.a
index f23e4e8..4570a5c 100644
Binary files a/MouseSdk/AliIotConnectKitSDK/AliIotConnectKit/ThirdLib/IotRtc/libiotRtc.a and b/MouseSdk/AliIotConnectKitSDK/AliIotConnectKit/ThirdLib/IotRtc/libiotRtc.a differ
diff --git a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate
index 6f27b06..8c43101 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.xcworkspace/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
index a37bea2..072f2d0 100644
--- a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
+++ b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
@@ -18,6 +18,53 @@
endingLineNumber = "210"
landmarkName = "writeDeviceInfoToBle(deviceSecret:)"
landmarkType = "7">
+
+
+
+
+
+
+
+
diff --git a/MouseSdk/MouseSdk/BleManager.h b/MouseSdk/MouseSdk/BleManager.h
index 6e3749e..3967af4 100644
--- a/MouseSdk/MouseSdk/BleManager.h
+++ b/MouseSdk/MouseSdk/BleManager.h
@@ -30,8 +30,6 @@ NS_ASSUME_NONNULL_BEGIN
/// - Parameter peripheral: èç设å¤
- (void)connectPeripheral:(CBPeripheral *)peripheral;
-/// å¼å§é´æ
-- (void)startAuthentication;
@end
NS_ASSUME_NONNULL_END
diff --git a/MouseSdk/MouseSdk/BleManager.m b/MouseSdk/MouseSdk/BleManager.m
index 68c64bb..7238ff9 100644
--- a/MouseSdk/MouseSdk/BleManager.m
+++ b/MouseSdk/MouseSdk/BleManager.m
@@ -109,6 +109,8 @@
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;
@@ -132,11 +134,11 @@
#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);
}
}
/// é´ææ°æ®åè°ï¼éè¦å°æ¤æ°æ®è½¬åç»èç设å¤
@@ -178,7 +180,6 @@
#pragma mark - public
/// è¿æ¥è®¾å¤
- (void)startScanDevice{
- NSLog(@"banben***** = %@",[[AiMouse shared] version]);
[self.centralManager scanForPeripheralsWithServices:nil options:@{CBCentralManagerScanOptionAllowDuplicatesKey : [NSNumber numberWithBool:NO]}];
}
@@ -193,11 +194,6 @@
[self.centralManager connectPeripheral:peripheral options:@{CBConnectPeripheralOptionNotifyOnConnectionKey : [NSNumber numberWithBool:YES]}];
}
-/// å¼å§é´æ
-- (void)startAuthentication{
- [[AiMouse shared] startAuthentication];
-}
-
#pragma mark - other
//èªå¨è¿æ¥ï¼è·åå·²é
对çèç,å第ä¸ä¸ªè¿æ¥
- (void)autoConnectDevice{
@@ -206,10 +202,10 @@
return;
}
NSArray *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];
diff --git a/MouseSdk/MouseSdk/ViewController.m b/MouseSdk/MouseSdk/ViewController.m
index 06e4dd9..58c0008 100644
--- a/MouseSdk/MouseSdk/ViewController.m
+++ b/MouseSdk/MouseSdk/ViewController.m
@@ -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];
@@ -45,15 +45,6 @@
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];
@@ -87,18 +78,12 @@
}
- (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?@"é´æç¶æï¼é´ææå":@"é´æç¶æï¼é´æå¤±è´¥";
});
}
diff --git "a/MouseSdk_Mac_V1.0.1/AiMouseSdk\346\216\245\345\217\243\346\226\207\346\241\243.pdf" "b/MouseSdk_Mac_V1.0.1/AiMouseSdk\346\216\245\345\217\243\346\226\207\346\241\243.pdf"
index d0fea61..1617375 100644
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\346\225\260\346\215\256\344\272\244\344\272\222\346\265\201\347\250\213.pdf" "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"
new file mode 100644
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\350\277\236\346\216\245\346\265\201\347\250\213.pdf" "b/MouseSdk_Mac_V1.0.1/MouseSdk\350\277\236\346\216\245\346\265\201\347\250\213.pdf"
new file mode 100644
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/\346\225\260\346\215\256\344\272\244\344\272\222\346\265\201\347\250\213.png" "b/MouseSdk_Mac_V1.0.1/\346\225\260\346\215\256\344\272\244\344\272\222\346\265\201\347\250\213.png"
deleted file mode 100644
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/\350\277\236\346\216\245\346\265\201\347\250\213.png" "b/MouseSdk_Mac_V1.0.1/\350\277\236\346\216\245\346\265\201\347\250\213.png"
deleted file mode 100644
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