BabyPeripheralManager.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. BabyBluetooth
  3. 简单易用的蓝牙ble库,基于CoreBluetooth 作者:刘彦玮
  4. https://github.com/coolnameismy/BabyBluetooth
  5. @brief 蓝牙外设模式实现类
  6. */
  7. // Created by 刘彦玮 on 15/12/12.
  8. // Copyright © 2015年 刘彦玮. All rights reserved.
  9. //
  10. #import <Foundation/Foundation.h>
  11. #import <CoreBluetooth/CoreBluetooth.h>
  12. #import "BabyToy.h"
  13. #import "BabySpeaker.h"
  14. @interface BabyPeripheralManager : NSObject<CBPeripheralManagerDelegate> {
  15. @public
  16. //回叫方法
  17. BabySpeaker *babySpeaker;
  18. }
  19. /**
  20. 添加服务
  21. */
  22. - (BabyPeripheralManager *(^)(NSArray *array))addServices;
  23. /**
  24. 启动广播
  25. */
  26. - (BabyPeripheralManager *(^)())startAdvertising;
  27. //外设管理器
  28. @property (nonatomic, strong) CBPeripheralManager *peripheralManager;
  29. @property (nonatomic, copy) NSString *localName;
  30. @property (nonatomic, strong) NSMutableArray *services;
  31. @end
  32. /**
  33. * 构造Characteristic,并加入service
  34. * service:CBService
  35. * param`ter for properties :option 'r' | 'w' | 'n' or combination
  36. * r CBCharacteristicPropertyRead
  37. * w CBCharacteristicPropertyWrite
  38. * n CBCharacteristicPropertyNotify
  39. * default value is rw Read-Write
  40. * paramter for descriptor:be uesd descriptor for characteristic
  41. */
  42. void makeCharacteristicToService(CBMutableService *service,NSString *UUID,NSString *properties,NSString *descriptor);
  43. /**
  44. * 构造一个包含初始值的Characteristic,并加入service,包含了初值的characteristic必须设置permissions和properties都为只读
  45. * make characteristic then add to service, a static characteristic mean it has a initial value .according apple rule, it must set properties and permissions to CBCharacteristicPropertyRead and CBAttributePermissionsReadable
  46. */
  47. void makeStaticCharacteristicToService(CBMutableService *service,NSString *UUID,NSString *descriptor,NSData *data);
  48. /**
  49. 生成CBService
  50. */
  51. CBMutableService* makeCBService(NSString *UUID);
  52. /**
  53. 生成UUID
  54. */
  55. NSString* genUUID();