--- /dev/null
+# MouseSDK接口文档\r
+\r
+\r
+\r
+## 文档修改记录\r
+\r
+| 版本 | 修改内容 | 修改人 | 修改时间 |\r
+| ----- | -------- | ------ | ---------- |\r
+| 1.0.0 | 初始版本 | 梁振营 | 2024-01-31 |\r
+\r
+\r
+\r
+\r
+\r
+## 引入依赖库\r
+\r
+将 AliIotConnectKit.framework 添加进项目中。\r
+\r
+## 相关权限配置\r
+\r
+因为sdk用到蓝牙权限,所以需要在info.plist进行相关配置\r
+\r
+```xml\r
+\r
+ <!-- 蓝牙 --> \r
+<key>NSBluetoothAlwaysUsageDescription</key> \r
+<string>App需要您的同意,才能访问蓝牙</string> \r
+```\r
+\r
+\r
+\r
+## 蓝牙相关接口\r
+\r
+```objective-c\r
+/// 配置SDK,每次连接上蓝牙设备后调用\r
+- (void)configSDK;\r
+\r
+/// 收到 蓝牙 数据\r
+/// - Parameter currData: 蓝牙数据\r
+- (void)handleReceivedData:(NSData *)data;\r
+\r
+/// 断开设备调用结束工作\r
+/// - Parameter completed: 清理结束回调\r
+- (void)done:(void(^ _Nonnull )(id _Nullable param))completed;\r
+```\r
+\r
+## 蓝牙相关代理\r
+\r
+AliIotSDKCallbackProtocol\r
+\r
+```objective-c\r
+/// 响应数据,返回给上层调用\r
+/// - Parameters:\r
+/// - currData: 当前发出去的数据\r
+/// - device: 蓝牙设备 MAC\r
+/// - error: 先判断空,再发送出去\r
+- (void)handleSendData:(NSData *)currData toDevice:(NSData *)mac error:(NSError * _Nullable)error;\r
+\r
+@optional\r
+/// 初始化结果\r
+/// - Parameter isFinish: 是否完成初始化\r
+- (void)sdkInitResult:(BOOL)isFinish;\r
+\r
+/// 输出日志\r
+/// - Parameter log: 日志信息\r
+- (void)handleLog:(NSString *)log;\r
+```\r
+\r
+## 示例\r
+\r
+- 设置代理\r
+\r
+ ```objective-c\r
+ AliIot.shareInstance.delegate = self;\r
+ AliIot.shareInstance.mapDelegate = self;\r
+ ```\r
+\r
+ \r
+\r
+- 蓝牙连接成功后,需要与蓝牙设备协商MTU。所以必须注意是连接上蓝牙设备后再调用configSDK方法。\r
+\r
+ ```objective-c\r
+ //配置sdk\r
+ - (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {\r
+ for (CBCharacteristic *characteristic in service.characteristics){\r
+ if ([characteristic.UUID.UUIDString isEqualToString:@"FED7"]) {\r
+ self.writeCha = characteristic;\r
+ //找到写入的uuid后,调用sdk配置方法\r
+ [AliIot.shareInstance configSDK];\r
+ }\r
+ if ([characteristic.UUID.UUIDString isEqualToString:@"FED8"]) {\r
+ self.notifyCha = characteristic;\r
+ [peripheral setNotifyValue:YES forCharacteristic:characteristic];\r
+ }\r
+ }\r
+ }\r
+ ```\r
+\r
+- 蓝牙连接断开后,必须调用done方法完成清理工作\r
+\r
+ ```objective-c\r
+ -(void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error{\r
+ //蓝牙断开要调用该方法清理sdk数据\r
+ [AliIot.shareInstance done:^(id _Nullable param) {\r
+ \r
+ }];\r
+ }\r
+ ```\r
+\r
+- 收到蓝牙设备传过来的数据,传给sdk处理\r
+\r
+ ```objective-c\r
+ - (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {\r
+ //收到蓝牙设备发送过来的数据,转发给sdk处理\r
+ [AliIot.shareInstance handleReceivedData:characteristic.value];\r
+ }\r
+ ```\r
+\r
+ \r
+\r
+ \r
+\r
+\r
+\r
+\r
+\r
--- /dev/null
+//
+// AiSdk.h
+// AiSdk
+//
+// Created by incar on 2024/2/19.
+//
+
+#import <Foundation/Foundation.h>
+
+//! Project version number for AiSdk.
+FOUNDATION_EXPORT double AiSdkVersionNumber;
+
+//! Project version string for AiSdk.
+FOUNDATION_EXPORT const unsigned char AiSdkVersionString[];
+
+// In this header, you should import all the public headers of your framework using statements like #import <AiSdk/PublicHeader.h>
+
+
18BF1E052B81E18800B8D90F /* ConnectKitVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 18BF1E042B81E18800B8D90F /* ConnectKitVC.swift */; };
18BF1E222B83066200B8D90F /* BleManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 18BF1E212B83066200B8D90F /* BleManager.m */; };
18BF1E762B832D2E00B8D90F /* ScanVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 18BF1E752B832D2E00B8D90F /* ScanVC.m */; };
+ 18BF1E7F2B83472D00B8D90F /* BleTools.m in Sources */ = {isa = PBXBuildFile; fileRef = 18BF1E7E2B83472D00B8D90F /* BleTools.m */; };
+ 18BF1E8A2B8362D300B8D90F /* AiSdk.h in Headers */ = {isa = PBXBuildFile; fileRef = 18BF1E892B8362D300B8D90F /* AiSdk.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 18BF1E8D2B8362D300B8D90F /* AiSdk.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 18BF1E872B8362D300B8D90F /* AiSdk.framework */; };
+ 18BF1E8E2B8362D300B8D90F /* AiSdk.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 18BF1E872B8362D300B8D90F /* AiSdk.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
+ 18F3235D2B8ED78300CABA2E /* ScanCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 18F3235C2B8ED78300CABA2E /* ScanCell.m */; };
+ 18F323622B8F13D700CABA2E /* LogVC.m in Sources */ = {isa = PBXBuildFile; fileRef = 18F323612B8F13D600CABA2E /* LogVC.m */; };
8A6657BD1406314D4CBB7CEF /* libPods-MouseSdk.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0311DF3AD67ED792549B96BD /* libPods-MouseSdk.a */; };
/* End PBXBuildFile section */
remoteGlobalIDString = 18BF1DC92B81AB7C00B8D90F;
remoteInfo = MouseSdk;
};
+ 18BF1E8B2B8362D300B8D90F /* PBXContainerItemProxy */ = {
+ isa = PBXContainerItemProxy;
+ containerPortal = 18BF1DC22B81AB7C00B8D90F /* Project object */;
+ proxyType = 1;
+ remoteGlobalIDString = 18BF1E862B8362D300B8D90F;
+ remoteInfo = AiSdk;
+ };
/* End PBXContainerItemProxy section */
+/* Begin PBXCopyFilesBuildPhase section */
+ 18BF1E8F2B8362D300B8D90F /* Embed Frameworks */ = {
+ isa = PBXCopyFilesBuildPhase;
+ buildActionMask = 2147483647;
+ dstPath = "";
+ dstSubfolderSpec = 10;
+ files = (
+ 18BF1E8E2B8362D300B8D90F /* AiSdk.framework in Embed Frameworks */,
+ );
+ name = "Embed Frameworks";
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXCopyFilesBuildPhase section */
+
/* Begin PBXFileReference section */
0311DF3AD67ED792549B96BD /* libPods-MouseSdk.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-MouseSdk.a"; sourceTree = BUILT_PRODUCTS_DIR; };
18BF1DCA2B81AB7C00B8D90F /* MouseSdk.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MouseSdk.app; sourceTree = BUILT_PRODUCTS_DIR; };
18BF1E212B83066200B8D90F /* BleManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BleManager.m; sourceTree = "<group>"; };
18BF1E742B832D2E00B8D90F /* ScanVC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScanVC.h; sourceTree = "<group>"; };
18BF1E752B832D2E00B8D90F /* ScanVC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ScanVC.m; sourceTree = "<group>"; };
+ 18BF1E7D2B83472D00B8D90F /* BleTools.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BleTools.h; sourceTree = "<group>"; };
+ 18BF1E7E2B83472D00B8D90F /* BleTools.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BleTools.m; sourceTree = "<group>"; };
+ 18BF1E872B8362D300B8D90F /* AiSdk.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AiSdk.framework; sourceTree = BUILT_PRODUCTS_DIR; };
+ 18BF1E892B8362D300B8D90F /* AiSdk.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AiSdk.h; sourceTree = "<group>"; };
+ 18F3235B2B8ED78300CABA2E /* ScanCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ScanCell.h; sourceTree = "<group>"; };
+ 18F3235C2B8ED78300CABA2E /* ScanCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ScanCell.m; sourceTree = "<group>"; };
+ 18F323602B8F13D600CABA2E /* LogVC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LogVC.h; sourceTree = "<group>"; };
+ 18F323612B8F13D600CABA2E /* LogVC.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LogVC.m; sourceTree = "<group>"; };
51DE1118FCBA78EBEE6FE2CD /* Pods-MouseSdk.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MouseSdk.release.xcconfig"; path = "Target Support Files/Pods-MouseSdk/Pods-MouseSdk.release.xcconfig"; sourceTree = "<group>"; };
811936622867478806C1A8BB /* Pods-MouseSdk.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-MouseSdk.debug.xcconfig"; path = "Target Support Files/Pods-MouseSdk/Pods-MouseSdk.debug.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
buildActionMask = 2147483647;
files = (
8A6657BD1406314D4CBB7CEF /* libPods-MouseSdk.a in Frameworks */,
+ 18BF1E8D2B8362D300B8D90F /* AiSdk.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
);
runOnlyForDeploymentPostprocessing = 0;
};
+ 18BF1E842B8362D300B8D90F /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
18BF1DCC2B81AB7C00B8D90F /* MouseSdk */,
18BF1DE22B81AB8000B8D90F /* MouseSdkTests */,
18BF1DEC2B81AB8000B8D90F /* MouseSdkUITests */,
+ 18BF1E882B8362D300B8D90F /* AiSdk */,
18BF1DCB2B81AB7C00B8D90F /* Products */,
723588BAA058E1012143D29F /* Pods */,
543EC4E5F9FC310D6B850947 /* Frameworks */,
18BF1DCA2B81AB7C00B8D90F /* MouseSdk.app */,
18BF1DDF2B81AB8000B8D90F /* MouseSdkTests.xctest */,
18BF1DE92B81AB8000B8D90F /* MouseSdkUITests.xctest */,
+ 18BF1E872B8362D300B8D90F /* AiSdk.framework */,
);
name = Products;
sourceTree = "<group>";
18BF1DD12B81AB7C00B8D90F /* ViewController.m */,
18BF1E742B832D2E00B8D90F /* ScanVC.h */,
18BF1E752B832D2E00B8D90F /* ScanVC.m */,
+ 18F3235B2B8ED78300CABA2E /* ScanCell.h */,
+ 18F3235C2B8ED78300CABA2E /* ScanCell.m */,
+ 18F323602B8F13D600CABA2E /* LogVC.h */,
+ 18F323612B8F13D600CABA2E /* LogVC.m */,
18BF1E042B81E18800B8D90F /* ConnectKitVC.swift */,
18BF1DD32B81AB7F00B8D90F /* Assets.xcassets */,
18BF1DD52B81AB7F00B8D90F /* Main.storyboard */,
children = (
18BF1E202B83066200B8D90F /* BleManager.h */,
18BF1E212B83066200B8D90F /* BleManager.m */,
+ 18BF1E7D2B83472D00B8D90F /* BleTools.h */,
+ 18BF1E7E2B83472D00B8D90F /* BleTools.m */,
);
path = Ble;
sourceTree = "<group>";
};
+ 18BF1E882B8362D300B8D90F /* AiSdk */ = {
+ isa = PBXGroup;
+ children = (
+ 18BF1E892B8362D300B8D90F /* AiSdk.h */,
+ );
+ path = AiSdk;
+ sourceTree = "<group>";
+ };
543EC4E5F9FC310D6B850947 /* Frameworks */ = {
isa = PBXGroup;
children = (
};
/* End PBXGroup section */
+/* Begin PBXHeadersBuildPhase section */
+ 18BF1E822B8362D300B8D90F /* Headers */ = {
+ isa = PBXHeadersBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 18BF1E8A2B8362D300B8D90F /* AiSdk.h in Headers */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXHeadersBuildPhase section */
+
/* Begin PBXNativeTarget section */
18BF1DC92B81AB7C00B8D90F /* MouseSdk */ = {
isa = PBXNativeTarget;
18BF1DC62B81AB7C00B8D90F /* Sources */,
18BF1DC72B81AB7C00B8D90F /* Frameworks */,
18BF1DC82B81AB7C00B8D90F /* Resources */,
+ 18BF1E8F2B8362D300B8D90F /* Embed Frameworks */,
);
buildRules = (
);
dependencies = (
+ 18BF1E8C2B8362D300B8D90F /* PBXTargetDependency */,
);
name = MouseSdk;
productName = MouseSdk;
productReference = 18BF1DE92B81AB8000B8D90F /* MouseSdkUITests.xctest */;
productType = "com.apple.product-type.bundle.ui-testing";
};
+ 18BF1E862B8362D300B8D90F /* AiSdk */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 18BF1E922B8362D300B8D90F /* Build configuration list for PBXNativeTarget "AiSdk" */;
+ buildPhases = (
+ 18BF1E822B8362D300B8D90F /* Headers */,
+ 18BF1E832B8362D300B8D90F /* Sources */,
+ 18BF1E842B8362D300B8D90F /* Frameworks */,
+ 18BF1E852B8362D300B8D90F /* Resources */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = AiSdk;
+ productName = AiSdk;
+ productReference = 18BF1E872B8362D300B8D90F /* AiSdk.framework */;
+ productType = "com.apple.product-type.framework";
+ };
/* End PBXNativeTarget section */
/* Begin PBXProject section */
CreatedOnToolsVersion = 15.0.1;
TestTargetID = 18BF1DC92B81AB7C00B8D90F;
};
+ 18BF1E862B8362D300B8D90F = {
+ CreatedOnToolsVersion = 15.0.1;
+ };
};
};
buildConfigurationList = 18BF1DC52B81AB7C00B8D90F /* Build configuration list for PBXProject "MouseSdk" */;
18BF1DC92B81AB7C00B8D90F /* MouseSdk */,
18BF1DDE2B81AB8000B8D90F /* MouseSdkTests */,
18BF1DE82B81AB8000B8D90F /* MouseSdkUITests */,
+ 18BF1E862B8362D300B8D90F /* AiSdk */,
);
};
/* End PBXProject section */
);
runOnlyForDeploymentPostprocessing = 0;
};
+ 18BF1E852B8362D300B8D90F /* Resources */ = {
+ isa = PBXResourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
+ 18BF1E7F2B83472D00B8D90F /* BleTools.m in Sources */,
18BF1E052B81E18800B8D90F /* ConnectKitVC.swift in Sources */,
+ 18F3235D2B8ED78300CABA2E /* ScanCell.m in Sources */,
+ 18F323622B8F13D700CABA2E /* LogVC.m in Sources */,
18BF1DD22B81AB7C00B8D90F /* ViewController.m in Sources */,
18BF1DD92B81AB7F00B8D90F /* main.m in Sources */,
18BF1E762B832D2E00B8D90F /* ScanVC.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
+ 18BF1E832B8362D300B8D90F /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
/* End PBXSourcesBuildPhase section */
/* Begin PBXTargetDependency section */
target = 18BF1DC92B81AB7C00B8D90F /* MouseSdk */;
targetProxy = 18BF1DEA2B81AB8000B8D90F /* PBXContainerItemProxy */;
};
+ 18BF1E8C2B8362D300B8D90F /* PBXTargetDependency */ = {
+ isa = PBXTargetDependency;
+ target = 18BF1E862B8362D300B8D90F /* AiSdk */;
+ targetProxy = 18BF1E8B2B8362D300B8D90F /* PBXContainerItemProxy */;
+ };
/* End PBXTargetDependency section */
/* Begin PBXVariantGroup section */
};
name = Release;
};
+ 18BF1E902B8362D300B8D90F /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CODE_SIGN_STYLE = Automatic;
+ COMBINE_HIDPI_IMAGES = YES;
+ CURRENT_PROJECT_VERSION = 1;
+ DEFINES_MODULE = YES;
+ DYLIB_COMPATIBILITY_VERSION = 1;
+ DYLIB_CURRENT_VERSION = 1;
+ DYLIB_INSTALL_NAME_BASE = "@rpath";
+ ENABLE_MODULE_VERIFIER = YES;
+ GENERATE_INFOPLIST_FILE = YES;
+ INFOPLIST_KEY_NSHumanReadableCopyright = "";
+ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
+ LD_RUNPATH_SEARCH_PATHS = (
+ "$(inherited)",
+ "@executable_path/../Frameworks",
+ "@loader_path/Frameworks",
+ );
+ MARKETING_VERSION = 1.0;
+ MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
+ MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20";
+ PRODUCT_BUNDLE_IDENTIFIER = zhihuishixun.AiSdk;
+ PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
+ SKIP_INSTALL = YES;
+ SWIFT_EMIT_LOC_STRINGS = YES;
+ VERSIONING_SYSTEM = "apple-generic";
+ VERSION_INFO_PREFIX = "";
+ };
+ name = Debug;
+ };
+ 18BF1E912B8362D300B8D90F /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ CODE_SIGN_STYLE = Automatic;
+ COMBINE_HIDPI_IMAGES = YES;
+ CURRENT_PROJECT_VERSION = 1;
+ DEFINES_MODULE = YES;
+ DYLIB_COMPATIBILITY_VERSION = 1;
+ DYLIB_CURRENT_VERSION = 1;
+ DYLIB_INSTALL_NAME_BASE = "@rpath";
+ ENABLE_MODULE_VERIFIER = YES;
+ GENERATE_INFOPLIST_FILE = YES;
+ INFOPLIST_KEY_NSHumanReadableCopyright = "";
+ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
+ LD_RUNPATH_SEARCH_PATHS = (
+ "$(inherited)",
+ "@executable_path/../Frameworks",
+ "@loader_path/Frameworks",
+ );
+ MARKETING_VERSION = 1.0;
+ MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
+ MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20";
+ PRODUCT_BUNDLE_IDENTIFIER = zhihuishixun.AiSdk;
+ PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
+ SKIP_INSTALL = YES;
+ SWIFT_EMIT_LOC_STRINGS = YES;
+ VERSIONING_SYSTEM = "apple-generic";
+ VERSION_INFO_PREFIX = "";
+ };
+ name = Release;
+ };
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
+ 18BF1E922B8362D300B8D90F /* Build configuration list for PBXNativeTarget "AiSdk" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 18BF1E902B8362D300B8D90F /* Debug */,
+ 18BF1E912B8362D300B8D90F /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
/* End XCConfigurationList section */
};
rootObject = 18BF1DC22B81AB7C00B8D90F /* Project object */;
<dict>
<key>SchemeUserState</key>
<dict>
+ <key>AiSdk.xcscheme_^#shared#^_</key>
+ <dict>
+ <key>orderHint</key>
+ <integer>1</integer>
+ </dict>
<key>MouseSdk.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
- (void)connectPeripheral:(CBPeripheral *)peripheral;
- (void)lpConnect;
+
+- (void)sendToBle:(NSData *)data;
@end
NS_ASSUME_NONNULL_END
// Created by incar on 2024/1/30.
//
+
+
#import "BleManager.h"
@interface BleManager ()<CBCentralManagerDelegate,CBPeripheralDelegate>
if ([self.scanArray containsObject:peripheral]){
return;
}
+ if(peripheral.name == nil){
+ return;
+ }
+ NSLog(@"%@",peripheral.name);
[self.scanArray insertObject:peripheral atIndex:0];
if(self.discoverDevice){
self.discoverDevice(peripheral, advertisementData);
}
#pragma mark - CBPeripheralDelegate
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {
- for (CBService *service in peripheral.services)
+ for (CBService *service in peripheral.services){
[peripheral discoverCharacteristics:@[[CBUUID UUIDWithString:@"FED7"],[CBUUID UUIDWithString:@"FED8"]] forService:service];
+ }
}
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {
}
#pragma mark - AliIotSDKCallbackProtocol
-- (void)handleSendData:(NSData *)data toDevice:(id)device error:(NSError *)error {
- NSLog(@"[send] %@",data);
- if (!error) {
- //收到sdk回调的数据,发送给蓝牙设备
- [self.connectPeripheral writeValue:data forCharacteristic:self.writeCha type:CBCharacteristicWriteWithoutResponse];
- }
-}
-- (void)handleLog:(NSString *)log {
- NSLog(@"[sdk log] %@",log);
-}
-
-- (void)sdkInitResult:(BOOL)isFinish{
- self.isSdkInitSuccess = isFinish;
- NSString *log = isFinish?@"初始化完成":@"初始化失败";
- NSLog(@"%@",log);
-}
-
-#pragma mark - AliIotSdkMapCallbackProtocol
-- (void)addCollect:(nonnull NSString *)collectionId content:(nonnull NSString *)jsonString {
- //传到服务器或者本地缓存
-}
-
-- (void)addTrajectory:(nonnull NSString *)trajectoryId content:(nonnull NSString *)jsonString {
- //传到服务器或者本地缓存
-}
-
-- (void)getCollectListView:(NSInteger)page pageSize:(NSInteger)pageSize {
- //从服务器或者本地缓存获取收藏数据,然后将数据传给sdk
-// [AliIot.shareInstance sendCollectList:jsonString];
-}
-
-- (void)getTrajectoryListView:(NSInteger)page pageSize:(NSInteger)pageSize {
- //从服务器或者本地缓存获取轨迹数据,然后将数据传给sdk
-// [AliIot.shareInstance sendTrajectoryList:jsonString];
-}
-
-- (void)removeCollect:(nonnull NSString *)collectionId {
- //从服务器或者本地缓存移除记录
-}
-
-- (void)removeTrajectory:(nonnull NSString *)trajectoryId {
- //从服务器或者本地缓存移除记录
-}
#pragma mark - public
- (void)startScanDevice{
//飞鸽书请求连接
- (void)lpConnect{
- NSData *data = [self tysm_dataWithHexString:@"000401"];
- NSMutableData *mData = NSMutableData.data;
- uint8_t cmd = 0x7f;
- [mData appendBytes:&cmd length:1];
- [mData appendData:data];
+// NSData *data = [self tysm_dataWithHexString:@"000000000401"];
+// NSMutableData *mData = NSMutableData.data;
+// uint8_t cmd = 0x7f;
+// [mData appendBytes:&cmd length:1];
+// [mData appendData:data];
// [AliIot.shareInstance handleReceivedData:mData.copy];
}
-- (NSData *)tysm_dataWithHexString:(NSString *)hexStr {
- hexStr = [hexStr stringByReplacingOccurrencesOfString:@" " withString:@""];
- hexStr = [hexStr lowercaseString];
- NSUInteger len = hexStr.length;
- if (!len) return nil;
- unichar *buf = malloc(sizeof(unichar) * len);
- if (!buf) return nil;
- [hexStr getCharacters:buf range:NSMakeRange(0, len)];
-
- NSMutableData *result = [NSMutableData data];
- unsigned char bytes;
- char str[3] = { '\0', '\0', '\0' };
- int i;
- for (i = 0; i < len / 2; i++) {
- str[0] = buf[i * 2];
- str[1] = buf[i * 2 + 1];
- bytes = strtol(str, NULL, 16);
- [result appendBytes:&bytes length:1];
- }
- free(buf);
- return result;
+
+- (void)sendToBle:(NSData *)data{
+ NSLog(@"[send] %@",data);
+ [self.connectPeripheral writeValue:data forCharacteristic:self.writeCha type:CBCharacteristicWriteWithoutResponse];
}
+
+
@end
--- /dev/null
+//
+// BleTools.h
+// MouseSdk
+//
+// Created by incar on 2024/2/19.
+//
+
+#import <Foundation/Foundation.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface BleTools : NSObject
++ (NSData *)dataWithHexString:(NSString *)hexStr;
+@end
+
+NS_ASSUME_NONNULL_END
--- /dev/null
+//
+// BleTools.m
+// MouseSdk
+//
+// Created by incar on 2024/2/19.
+//
+
+#import "BleTools.h"
+
+@implementation BleTools
++ (NSData *)dataWithHexString:(NSString *)hexStr {
+ hexStr = [hexStr stringByReplacingOccurrencesOfString:@" " withString:@""];
+ hexStr = [hexStr lowercaseString];
+ NSUInteger len = hexStr.length;
+ if (!len) return nil;
+ unichar *buf = malloc(sizeof(unichar) * len);
+ if (!buf) return nil;
+ [hexStr getCharacters:buf range:NSMakeRange(0, len)];
+
+ NSMutableData *result = [NSMutableData data];
+ unsigned char bytes;
+ char str[3] = { '\0', '\0', '\0' };
+ int i;
+ for (i = 0; i < len / 2; i++) {
+ str[0] = buf[i * 2];
+ str[1] = buf[i * 2 + 1];
+ bytes = strtol(str, NULL, 16);
+ [result appendBytes:&bytes length:1];
+ }
+ free(buf);
+ return result;
+}
+@end
--- /dev/null
+//
+// LogVC.h
+// MouseSdk
+//
+// Created by incar on 2024/2/28.
+//
+
+#import <Cocoa/Cocoa.h>
+
+NS_ASSUME_NONNULL_BEGIN
+
+@interface LogVC : NSViewController
+
+@end
+
+NS_ASSUME_NONNULL_END
--- /dev/null
+//
+// LogVC.m
+// MouseSdk
+//
+// Created by incar on 2024/2/28.
+//
+
+#import "LogVC.h"
+#import "Ble/BleManager.h"
+#import "Ble/BleTools.h"
+@interface LogVC()
+@property (nonatomic,strong) NSTextField *textField;
+@end
+
+@implementation LogVC
+- (void)viewDidLoad {
+ [super viewDidLoad];
+ // Do view setup here.
+ [self setupViews];
+ [self setupBle];
+}
+- (void)loadView{
+ self.title = @"扫描设备";
+ self.view = [[NSView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
+}
+- (void)setupViews{
+
+}
+- (void)setupBle{
+ BleManager *manager = [BleManager shared];
+ __weak typeof(self) weakSelf= self;
+
+}
+
+@end
--- /dev/null
+//
+// ScanCell.h
+// MouseSdk
+//
+// Created by incar on 2024/2/28.
+//
+
+#import <Cocoa/Cocoa.h>
+#import <CoreBluetooth/CoreBluetooth.h>
+NS_ASSUME_NONNULL_BEGIN
+
+@interface ScanCell : NSTableCellView
+@property(nonatomic,strong)CBPeripheral *peripheral;
+@property(nonatomic,strong)void (^connecCallBack)(CBPeripheral *peripheral);
+@end
+
+NS_ASSUME_NONNULL_END
--- /dev/null
+//
+// ScanCell.m
+// MouseSdk
+//
+// Created by incar on 2024/2/28.
+//
+
+#import "ScanCell.h"
+
+@interface ScanCell()
+@property(nonatomic,strong)NSTextField *label;
+@property(nonatomic,strong)NSButton *connectBtn;
+@end
+
+@implementation ScanCell
+- (instancetype)initWithFrame:(CGRect)frame
+{
+ self = [super initWithFrame:frame];
+ if (self) {
+ [self setupView];
+ }
+ return self;
+}
+
+- (void)drawRect:(NSRect)dirtyRect{
+ [super drawRect:dirtyRect];
+}
+
+- (void)setupView{
+ NSTextField *label = [[NSTextField alloc] initWithFrame:CGRectMake(0, 10, 200, 35)];
+ label.editable = NO;
+ label.bordered = NO;
+ label.stringValue = @"000000";
+ self.label = label;
+ [self addSubview:label];
+
+ NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(250, 5, 100, 35)];
+ btn.bordered = true;
+ btn.title = @"连接";
+ [btn setTarget:self];
+ [btn setAction:@selector(connetAction)];
+ btn.state = 1;
+ [self addSubview:btn];
+ self.connectBtn = btn;
+
+
+}
+
+-(void)setPeripheral:(CBPeripheral *)peripheral{
+ _peripheral = peripheral;
+ self.label.stringValue = peripheral.name;
+ [self.label sizeToFit];
+ CGRect f = self.label.frame;
+ f.origin.y = (self.bounds.size.height - f.size.height)/2;
+ self.label.frame = f;
+}
+
+- (void)connetAction{
+ if (self.connecCallBack) {
+ self.connecCallBack(self.peripheral);
+ }
+}
+@end
@interface ScanVC : NSViewController
+
@end
NS_ASSUME_NONNULL_END
//
#import "ScanVC.h"
-
-@interface ScanVC ()
-
+#import "ScanCell.h"
+#import "Ble/BleManager.h"
+#import "Ble/BleTools.h"
+@interface ScanVC ()<NSTableViewDelegate,NSTableViewDataSource>
+@property (nonatomic,strong) NSTableView *tableView;
+@property (nonatomic,strong) NSMutableArray<CBPeripheral *> *scanArray;
@end
@implementation ScanVC
+-(NSMutableArray<CBPeripheral *> *)scanArray{
+ if (_scanArray == nil) {
+ _scanArray = [[NSMutableArray alloc] init];
+ }
+ return _scanArray;
+}
- (void)viewDidLoad {
[super viewDidLoad];
// Do view setup here.
+ self.title = @"扫描设备";
+ [self tableViewSetting];
+ [self setupBle];
+}
+- (void)loadView{
+ self.view = [[NSView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
+}
+
+- (void)tableViewSetting{
+ CALayer *viewLayer = [CALayer layer];
+ NSView *backgroundView= [[NSView alloc]init];
+ [backgroundView setWantsLayer:YES];
+ [backgroundView setLayer:viewLayer];
+ backgroundView.layer.backgroundColor = [NSColor greenColor].CGColor;
+ [backgroundView setNeedsDisplay:YES];
+ [self.view addSubview:backgroundView];
+
+ //实现tableview的滚动效果
+ NSScrollView *scrollView = [[NSScrollView alloc] initWithFrame:self.view.bounds];
+ scrollView.backgroundColor = [NSColor redColor];
+ [scrollView setDrawsBackground:NO];//不画背景(背景默认画成白色)
+ [scrollView setHasVerticalScroller:YES];//有垂直滚动条
+ //[_tableContainer setHasHorizontalScroller:YES]; //有水平滚动条
+ scrollView.autohidesScrollers = YES;//自动隐藏滚动条(滚动的时候出现)
+ [self.view addSubview:scrollView];
+
+ self.tableView = [[NSTableView alloc] initWithFrame:scrollView.bounds];
+ [scrollView setDocumentView:self.tableView];
+
+ NSTableColumn *column1 = [[NSTableColumn alloc] initWithIdentifier:@"columnFrist"];
+ column1.title = @"设备名称";
+ [column1 setWidth:self.tableView.bounds.size.width];
+ [self.tableView addTableColumn:column1];
+
+// self.tableView.focusRingType = NSFocusRingTypeNone;//tableview获得焦点时的风格
+// self.tableView.selectionHighlightStyle = NSTableViewSelectionHighlightStyleRegular;//行高亮的风格
+// self.tableView.backgroundColor = [NSColor greenColor];
+// self.tableView.usesAlternatingRowBackgroundColors = YES; //背景颜色的交替,一行白色,一行灰色。设置后,原来设置的 backgroundColor 就无效了。
+ self.tableView.delegate = self;
+ self.tableView.dataSource = self;
+ self.tableView.gridStyleMask = NSTableViewSolidHorizontalGridLineMask;
+}
+
+- (void)setupBle{
+ BleManager *manager = [BleManager shared];
+ __weak typeof(self) weakSelf= self;
+// __weak typeof(BleManager) *weakManager = manager;
+ manager.discoverDevice = ^(CBPeripheral *peripheral,NSDictionary *advertisementData){
+ if ([weakSelf.scanArray containsObject:peripheral]){
+ return;
+ }
+ if(peripheral.name.length == 0){
+ return;
+ }
+ [weakSelf.scanArray addObject:peripheral];
+ [weakSelf.tableView reloadData];
+// NSLog(@"%@",peripheral.name);
+// iMouse Ublue_BT895x
+// if([peripheral.name isEqualToString:@"iMouse"]){
+// [weakManager connectPeripheral:peripheral];
+// [weakManager stopScanDevice];
+// }
+ };
+ manager.didConnectDevice = ^(CBPeripheral * _Nonnull peripheral) {
+ NSLog(@"连接成功");
+ [weakSelf dismissViewController:weakSelf];
+ };
+ [manager startScanDevice];
+}
+
+- (void)connectDevice:(CBPeripheral *)peripheral{
+ [[BleManager shared] connectPeripheral:peripheral];
+}
+#pragma mark - NSTableViewDelegate,NSTableViewDataSource
+-(NSInteger)numberOfRowsInTableView:(NSTableView *)tableView{
+ return self.scanArray.count;
+}
+
+-(NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
+// NSString *columnID = tableColumn.identifier;
+// NSString *strIdt = @"NSTableCellView";
+// NSTableCellView *cell = [tableView makeViewWithIdentifier:strIdt owner:self];
+// if (!cell) {
+// cell = [[NSTableCellView alloc]init];
+// cell.identifier = strIdt;
+// }
+// cell.wantsLayer = YES;
+// cell.textField.stringValue = [NSString stringWithFormat:@"cell %ld",(long)row];
+//
+// return cell;
+ ScanCell *cell = [[ScanCell alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, 44)];
+ cell.peripheral = self.scanArray[row];
+ __weak typeof(self) weakSelf = self;
+ cell.connecCallBack = ^(CBPeripheral * _Nonnull peripheral) {
+ [weakSelf connectDevice:peripheral];
+ };
+ return cell;
+}
+-(CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row{
+ return 44;
}
@end
#import "ViewController.h"
#import "ScanVC.h"
#import "Ble/BleManager.h"
+#import "Ble/BleTools.h"
//#import "AliIotConnectKit/AliIotConnectKit.h"
@implementation ViewController
+
+
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
+ self.title = @"AI SDK";
{
- NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(20, 60, 100, 45)];
+ NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(100, self.view.bounds.size.height - 40, 100, 45)];
btn.bordered = true;
- btn.title = @"扫描"; // 按钮文字
+ btn.title = @"扫描";
[btn setTarget:self];
- [btn setAction:@selector(scanAction)]; // 按钮触发的方法
+ [btn setAction:@selector(scanAction)];
btn.state = 1;
[self.view addSubview:btn];
}
{
- NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(100, 100, 100, 45)];
+ NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(100, self.view.bounds.size.height - 150, 100, 45)];
btn.bordered = true;
- btn.title = @"fgs"; // 按钮文字
+ btn.title = @"initSDK";
[btn setTarget:self];
- [btn setAction:@selector(checkFGSStatus)]; // 按钮触发的方法
- btn.state = 1;
- [self.view addSubview:btn];
- }
- {
- NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(300, 100, 100, 45)];
- btn.bordered = true;
- btn.title = @"connectLp"; // 按钮文字
- [btn setTarget:self];
- [btn setAction:@selector(connectLp)]; // 按钮触发的方法
+ [btn setAction:@selector(initSDK)];
btn.state = 1;
[self.view addSubview:btn];
}
+// {
+// NSButton *btn = [[NSButton alloc]initWithFrame:NSMakeRect(300, 100, 100, 45)];
+// btn.bordered = true;
+// btn.title = @"connectLp"; // 按钮文字
+// [btn setTarget:self];
+// [btn setAction:@selector(connectLp)]; // 按钮触发的方法
+// btn.state = 1;
+// [self.view addSubview:btn];
+// }
[self setupBleManger];
}
}
- (void)scanAction{
- [[BleManager shared] startScanDevice];
-
+ ScanVC *vc = [[ScanVC alloc] initWithNibName:nil bundle:nil];
+ [self presentViewControllerAsModalWindow:vc];
+// [[BleManager shared] startScanDevice];
}
- (void)setupBleManger{
BleManager *manager = [BleManager shared];
- __weak typeof(ViewController) *weakSelf = self;
__weak typeof(BleManager) *weakManager = manager;
manager.discoverDevice = ^(CBPeripheral *peripheral,NSDictionary *advertisementData){
if(peripheral.name.length == 0){
return;
}
- NSLog(@"%@",peripheral.name);
- if([peripheral.name isEqualToString:@"Ublue_BT895x"]){
+// NSLog(@"%@",peripheral.name);
+// iMouse Ublue_BT895x
+ if([peripheral.name isEqualToString:@"iMouse"]){
[weakManager connectPeripheral:peripheral];
[weakManager stopScanDevice];
}
NSLog(@"连接成功");
};
-// [manager startScanDevice];
}
-
+- (void)initSDK{
+ NSData *data = [BleTools dataWithHexString:@"0000004f0000"];
+ [[BleManager shared] sendToBle:data];
+}
//- (void)checkFGSStatus{
// [AliConnectMananger_C.shared checkFgsStateWithResult:^(BOOL isSuccess, NSDictionary<NSString *,id> * dict) {
// NSLog(@"FGS成功 = %@,dict = %@",[NSNumber numberWithBool:isSuccess],dict);
# Uncomment the next line to define a global platform for your project
# platform :ios, '11.0'
-#platform :osx, '11.0'
-
-#target 'AliIotSdk' do
-# # Comment the next line if you don't want to use dynamic frameworks
-# use_frameworks!
-## platform :osx, '11.0'
-#
-# # Pods for AliIotSdk
-## pod 'NBULog'
-## pod 'fishhook'
-## pod 'Bugly'
-# target 'AliIotSdkTests' do
-# # Pods for testing
-# end
-#
-#end
+platform :osx, '11.0'
+#source 'https://kkgithub.com/CocoaPods/Specs.git'
+#source 'https://kkgithub.com/CocoaPods/Specs.git'
+# source 'https://gitee.com/mirrors/CocoaPods-Specs.git'
target 'MouseSdk' do
# Comment the next line if you don't want to use dynamic frameworks
-
+ pod 'Masonry'