IOS系列——蓝牙(中心)2

CBCentralManager 与之对应的是CBPeripheraimanager

CBCentralManager对应的几种状态

typedef NS_ENUM(NSInteger, CBCentralManagerState) {
// 初始的时候是未知的(刚刚创建的时候)

CBCentralManagerStateUnknown = 0,

//正在重置状态 CBCentralManagerStateResetting, //设备不支持的状态 CBCentralManagerStateUnsupported, // 设备未授权状态 CBCentralManagerStateUnauthorized, //设备关闭状态 CBCentralManagerStatePoweredOff, // 设备开启状态 -- 可用状态 CBCentralManagerStatePoweredOn, };
代理
@property(weak, nonatomic) id<CBCentralManagerDelegate> delegate;
// 初始化方法-参数-delegate-可以放到多线程里面去创建做更多的事情-queue
- (id)initWithDelegate:(id<CBCentralManagerDelegate>)delegate queue:(dispatch_queue_t)queue;
//初始化方法-参数-options指定这个manager
- (id)initWithDelegate:(id<CBCentralManagerDelegate>)delegate queue:(dispatch_queue_t)queue options:(NSDictionary *)options
//检索外围设备通过传入一个UUID数组
- (void)retrievePeripherals:(NSArray *)peripheralUUIDs 
//检索外围设备通过传入一个identifiers数组
- (NSArray *)retrievePeripheralsWithIdentifiers:(NSArray *)identifiers
// 检索已连接的外围设备
- (void)retrieveConnectedPeripherals
//通过服务的UUID数组返回已经连接的服务数组
- (NSArray *)retrieveConnectedPeripheralsWithServices:(NSArray *)serviceUUIDs
// serviceUUIDs是一个CBUUID数组,如果serviceUUIDs是nil为空的话所有的被发现的peripheral将要被返回
- (void)scanForPeripheralsWithServices:(NSArray *)serviceUUIDs options:(NSDictionary *)options
// 停止扫描
- (void)stopScan
//通过options指定的选项去连接peripheral
- (void)connectPeripheral:(CBPeripheral *)peripheral options: (NSDictionary *)options
//取消一个活跃的或者等待连接的peripheral的连接
- (void)cancelPeripheralConnection:(CBPeripheral *)peripheral

 必须实现的方法
//仅仅在CBCentralManagerStatePoweredOn的时候可用当central的状态是OFF的时候所有与中心连接的peripheral都将无效并且都要重新连接,central的初始状态时是Unknown
- (void)centralManagerDidUpdateState:(CBCentralManager *)central;

//central提供信息,dict包含了应用程序关闭是系统保存的central的信息,用dic去恢复central

//app状态的保存或者恢复,这是第一个被调用的方法当APP进入后台去完成一些蓝牙有关的工作设置,使用这个方法同步app状态通过蓝牙系统

- (void)centralManager:(CBCentralManager *)central willRestoreState:(NSDictionary *)dict

//*  @param central      The central manager providing this information.

 *  @param peripherals  A list of <code>CBPeripheral</code> objects.

改方法返回一个结果当{@link retrievePeripherals} 被调用,与周边,中央能够匹配UUID

- (void)centralManager:(CBCentralManager *)central didRetrievePeripherals:(NSArray *)peripherals

//peripherals表示当前连接central的所有peripherals

//这个方法返回一个结果,当retrieveConnectedPeripherals被调用是

- (void)centralManager:(CBCentralManager *)central didRetrieveConnectedPeripherals:(NSArray *)peripherals
- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral
- (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error
- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值