CBCentralManager Class 的相关分析

Overview

总体概述

CBCentralManager objects are used to manage discovered or connected remote peripheral devices (represented by CBPeripheral objects), including scanning for, discovering, and connecting to advertising peripherals.

CBCentralManager 对象负责管理外设的发现或连接,包括扫描、发现、连接正在广播的外设。

Before you call CBCentralManager methods, the state of the central manager object must be powered on, as indicated by theCBCentralManagerStatePoweredOn constant. This state indicates that the central device (your iPhone or iPad, for instance) supports Bluetooth low energy and that Bluetooth is on and available to use.

在调用CBCentralManager 方法前,我们必须查看中央管理器的状态是否为打开状态(CBCentralManagerStatePoweredOn)。如果是该状态,表明该中心设备(你的iphone或者ipad)是支持蓝牙低功耗4.0的。

Tasks 任务

Initializing a Central Manager  初始化中央管理器

  • – initWithDelegate:queue:
  • – initWithDelegate:queue:options:
  • - (id)initWithDelegate:(id<CBCentralManagerDelegate>)delegate queue:(dispatch_queue_t)queue options:(NSDictionary *)options
  • 方法说明:delegate代理:接受中心事件        queue:指明在哪个队列处理事件,为nil时表示在主线程处理      
  • options:有一下两个选择
  • NSString *const CBCentralManagerOptionShowPowerAlertKey;用该参量出事中央管理器时,当蓝牙开关未打开时会弹出警告框。
    NSString *const CBCentralManagerOptionRestoreIdentifierKey;该参量包含一个指定中央管理器的uid

Establishing or Canceling Connections with Peripherals 连接外设  或者 取消外设连接

Retrieving Lists of Peripherals  整理出外设列表

Scanning or Stopping Scans of Peripherals 扫描或者停止扫描外设

Monitoring Properties

  •    state  property
  • 返回一个central manager的当前状态,
  • Discussion 讨论

    When a central manager object is initially created, the default value of this property is CBCentralManagerStateUnknown

    当一个中央管理器对象初始化时,他的默认值是CBCentralManagerStateUnknown

    As the central manager’s state changes, the central manager updates the value of this property and calls the centralManagerDidUpdateState:

    当中央管理器状态改变时,会调用centralManagerDidUpdateState:委托方法

        delegate  property

    Central Manager State中央管理器状态

    Values representing the current state of a central manager object.

    typedef enum {
       CBCentralManagerStateUnknown = 0, 未知
       CBCentralManagerStateResetting,   复位
       CBCentralManagerStateUnsupported, 表明设备不支持蓝牙低功耗 
       CBCentralManagerStateUnauthorized,该应用程序是无权使用蓝牙低功耗。
       CBCentralManagerStatePoweredOff,  关闭状态
       CBCentralManagerStatePoweredOn,   打开状态
    } CBCentralManagerState

Central Manager State

Values representing the current state of a central manager object.

typedef enum {
   CBCentralManagerStateUnknown = 0,
   CBCentralManagerStateResetting,
   CBCentralManagerStateUnsupported,
   CBCentralManagerStateUnauthorized,
   CBCentralManagerStatePowe
原文地址:https://www.cnblogs.com/songfeixiang/p/3733702.html