You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
96 lines
2.2 KiB
96 lines
2.2 KiB
// |
|
// Bluetooth.h |
|
// tongxin |
|
// |
|
// Created by ecell on 2022/11/3. |
|
// Copyright © 2022 xTT. All rights reserved. |
|
// |
|
|
|
#import <Foundation/Foundation.h> |
|
#import <CoreBluetooth/CoreBluetooth.h> |
|
#import <UIKit/UIKit.h> |
|
#import <YYCache/YYCache.h> |
|
#import "BLEModel.h" |
|
|
|
/** 连接成功通知 */ |
|
#define BluetoothNotificationAtConnectSuccess @"BluetoothNotificationAtConnectSuccess" |
|
/** 连接DFU成功通知 */ |
|
#define BluetoothNotificationAtDFUConnectSuccess @"BluetoothNotificationAtDFUConnectSuccess" |
|
/** 连接失败通知 */ |
|
#define BluetoothNotificationAtConnectFail @"BluetoothNotificationAtConnectFail" |
|
/** 断开连接通知 */ |
|
#define BluetoothNotificationAtDisconnect @"BluetoothNotificationAtDisconnect" |
|
/** 重连通知 */ |
|
#define BluetoothNotificationAtReconnect @"BluetoothNotificationAtReconnect" |
|
/** 蓝牙开关关闭 */ |
|
#define BluetoothNotificationAtPowerOff @"BluetoothNotificationAtPowerOff" |
|
|
|
/// 清除设备 |
|
#define DISConnectedCurrenDevice @"DISConnectedCurrenDevice" |
|
|
|
NS_ASSUME_NONNULL_BEGIN |
|
|
|
@class BLEModel; |
|
@interface Bluetooth : NSObject |
|
|
|
|
|
@property (nonatomic,strong) YYCache *cache; |
|
|
|
@property (assign, nonatomic) CBManagerState mBleManagerState; |
|
@property (strong, nonatomic) CBPeripheral *__nullable mBlePeripheral; |
|
@property (strong, nonatomic) NSString *lastUUID; // 上一次连接的蓝牙UUID |
|
@property (strong, nonatomic) NSString *__nullable lastBleMacAddress; // 上一次连接的蓝牙地址 |
|
@property (nonatomic ,strong) BLEModel *currenModel; |
|
/// 是否已连接 |
|
@property (nonatomic ,assign) BOOL isConnected; |
|
|
|
/** 写的特征值 */ |
|
@property (nullable, nonatomic, strong) CBCharacteristic *writecharacteristic; |
|
|
|
/** 写的特征值 */ |
|
@property (nullable, nonatomic, strong) CBCharacteristic *writecharacteristicq; |
|
|
|
|
|
|
|
/** |
|
* 单例 |
|
*/ |
|
+ (instancetype)shareInstance; |
|
|
|
/** |
|
开始搜索 |
|
*/ |
|
-(void)startScanBLE; |
|
|
|
/** |
|
停止搜索 |
|
*/ |
|
-(void)stopScanBLE; |
|
|
|
/** |
|
连接设备 |
|
@param bleModel 蓝牙设备类 |
|
*/ |
|
-(void)connectBLE:(BLEModel*)bleModel; |
|
|
|
/** |
|
断开连接 |
|
*/ |
|
-(void)disconnectBLE; |
|
|
|
/** |
|
使用UUID,重连设备。 |
|
*/ |
|
-(void)connectPeripheralWithUUID; |
|
|
|
/// 移除设备 |
|
- (void)disConnectedCurrenDevice; |
|
|
|
- (void)writeCheckBleWithBle:(NSString *)cmd; |
|
|
|
|
|
|
|
|
|
@end |
|
|
|
NS_ASSUME_NONNULL_END
|
|
|