HeartBLEManager.m 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //
  2. // HeartBLEManager.m
  3. // HeartTestDemo
  4. //
  5. // Created by 郭志奇 on 2019/8/7.
  6. // Copyright © 2019 郭志奇. All rights reserved.
  7. //
  8. #import "HeartBLEManager.h"
  9. #import "HeartBLEDevice.h"
  10. #import "HeartBLEDriver.h"
  11. #import <CoreBluetooth/CoreBluetooth.h>
  12. @interface HeartBLEManager()<BLEDriveDelegate>
  13. {
  14. id __weak theDelegate;
  15. HeartBLEDriver* BLEDriver;
  16. }
  17. @end
  18. @implementation HeartBLEManager
  19. + (instancetype)sharedInstance{
  20. static HeartBLEManager *share = nil;
  21. static dispatch_once_t onceToken;
  22. dispatch_once(&onceToken, ^{
  23. share = [[HeartBLEManager alloc]init];
  24. });
  25. return share;
  26. }
  27. - (instancetype)init
  28. {
  29. self = [super init];
  30. if (self) {
  31. BLEDriver = [HeartBLEDriver sharedInstance];
  32. [BLEDriver setDelegate:self];
  33. }
  34. return self;
  35. }
  36. #pragma mark - Public Method
  37. - (void)setDelegate:(id)delegate{
  38. theDelegate = delegate;
  39. }
  40. - (BOOL)isBLEPoweredOn{
  41. return BLEDriver.isBLEPoweredOn;
  42. }
  43. - (NSArray *)connectedDevices{
  44. return BLEDriver->connectedDevices.copy;
  45. }
  46. - (void)StartScanDevice
  47. {
  48. [BLEDriver StartScanForDevice];
  49. }
  50. - (void)stopScan{
  51. [BLEDriver stopScan];
  52. }
  53. - (void)closeAllDevice{
  54. [BLEDriver closelAllDevice];
  55. }
  56. #pragma mark - BLEDriverDelegate
  57. - (void)onDeviceFound:(NSArray *)deviceArray{
  58. if ([theDelegate respondsToSelector:@selector(onDeviceFound:)]) {
  59. [theDelegate onDeviceFound:deviceArray];
  60. }
  61. }
  62. - (void)isConnected:(BOOL)isConnected withDevice:(HeartBLEDevice *)device{
  63. if ([theDelegate respondsToSelector:@selector(isConnected:withDevice:)]) {
  64. [theDelegate isConnected:isConnected withDevice:device];
  65. }
  66. }
  67. - (void)disconnected:(HeartBLEDevice *)device{
  68. if ([theDelegate respondsToSelector:@selector(disconnected:)]) {
  69. [theDelegate disconnected:device];
  70. }
  71. }
  72. @end