CBCentralManager Class 的相关分析

本文详细介绍了CBCentralManager的使用方法,包括初始化、连接与断开连接、扫描外设等核心功能,并解释了如何通过代理方法获取状态更新及外设信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值