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
- NSString *const CBCentralManagerOptionShowPowerAlertKey;用该参量出事中央管理器时,当蓝牙开关未打开时会弹出警告框。
Establishing or Canceling Connections with Peripherals 连接外设 或者 取消外设连接
– connectPeripheral:options:
- - (void)connectPeripheral:(CBPeripheral *)peripheral options:(NSDictionary *)options
- 参数说明:
- peripheral:中央管理器想要连接的外设对象
- options:
还没搞明白- NSString *const CBConnectPeripheralOptionNotifyOnConnectionKey;
- NSString *const CBConnectPeripheralOptionNotifyOnDisconnectionKey;
- NSString *const CBConnectPeripheralOptionNotifyOnNotificationKey;
讨论:当连接外设成功时要调用在委托对象中实现的方法:
centralManager:didConnectPeripheral:
- NSString *const CBConnectPeripheralOptionNotifyOnConnectionKey;
- 当连接外设失败时要调用在委托对象中实现的方法:
centralManager:didFailToConnectPeripheral:error:
– cancelPeripheralConnection:
- - (void)cancelPeripheralConnection:(CBPeripheral *)peripheral
- 取消外设连接
- 该方法调用后会触发委托中的方法:centralManager:didDisconnectPeripheral:error:
Retrieving Lists of Peripherals 整理出外设列表
– retrieveConnectedPeripheralsWithServices:
- - (NSArray *)retrieveConnectedPeripheralsWithServices:(NSArray *)serviceUUIDs
- 参数说明:
- serviceUUIDs
表示服务uuids的列表 - 返回值:从连接的设备(可能有多个app连接不同的蓝牙设备)中,根据服务列表,返回这些服务的数组(也就是找到我们指定的服务设备,整理到一个数组中返回)
– retrievePeripheralsWithIdentifiers:
- - (NSArray *)retrievePeripheralsWithIdentifiers:(NSArray *)identifiers
- 和上一个相识,只不过这里是指定的标示符数组
– retrieveConnectedPeripherals
Deprecated
in iOS 7.0- 该方法整理出所有连接到中央设备(比如iphone)的外设,返回一个数组(该数组包含了所有app连接的外设列表)
- 该方法会触发调用委托中的方法
centralManager:didRetrieveConnectedPeripherals:
– retrievePeripherals:
Deprecated
in iOS 7.0
Scanning or Stopping Scans of Peripherals 扫描或者停止扫描外设
– scanForPeripheralsWithServices:options:
- - (void)scanForPeripheralsWithServices:(NSArray *)serviceUUIDs options:(NSDictionary *)options
- 参数说明:
- serviceUUIDs:代表该app所感兴趣的服务uuids数组(也就是该app想要连接的外设)
- 每当扫描到一个外设,就会调用委托对象中的方法:
centralManager:didDiscoverPeripheral:advertisementData:RSSI:
– stopScan 停止扫描
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
propertyCentral Manager State中央管理器状态
Values representing the current state of a central manager object.
- typedef enum {
- CBCentralManagerStateUnknown = 0, 未知
- CBCentralManagerStateResetting, 复位
- CBCentralManagerStateUnsupported, 表明设备不支持蓝牙低功耗
- CBCentralManagerStateUnauthorized,该应用程序是无权使用蓝牙低功耗。
- CBCentralManagerStatePoweredOff, 关闭状态
- CBCentralManagerStatePoweredOn, 打开状态
- } CBCentralManagerState
- typedef enum {
Central Manager State
Values representing the current state of a central manager object.
- typedef enum {
- CBCentralManagerStateUnknown = 0,
- CBCentralManagerStateResetting,
- CBCentralManagerStateUnsupported,
- CBCentralManagerStateUnauthorized,
- CBCentralManagerStatePowe
CBCentralManager Class 的相关分析的更多相关文章
- 多视图学习利器----CCA(典型相关分析)及MATLAB实现
Hello,我是你们人见人爱花见花开的小花.又和大家见面了,今天我们来聊一聊多视图学习利器------CCA. 一 典型相关分析的基本思想 当我们研究两个变量x和y之间的相关关系的时候,相关系数(相关 ...
- SPSS数据分析—基于最优尺度变换的典型相关分析
传统的典型相关分析只能考虑变量之间的线性相关情况,且必须为连续变量,而我们依然可以使用最优尺度变换来拓展其应用范围,使其可以分析非线性相关.数据为分类数据等情况,并且不再仅限于两个变量间的分析, 虽然 ...
- SPSS数据分析—典型相关分析
我们已经知道,两个随机变量间的相关关系可以用简单相关系数表示,一个随机变量和多个随机变量的相关关系可以用复相关系数表示,而如果需要研究多个随机变量和多个随机变量间的相关关系,则需要使用典型相关分析. ...
- SPSS数据分析—相关分析
相关系数是衡量变量之间相关程度的度量,也是很多分析的中的当中环节,SPSS做相关分析比较简单,主要是区别如何使用这些相关系数,如果不想定量的分析相关性的话,直接观察散点图也可以. 相关系数有一些需要注 ...
- 中国各城市PM2.5数据间的相关分析
code{white-space: pre;} pre:not([class]) { background-color: white; }if (window.hljs && docu ...
- Jordan Lecture Note-12: Kernel典型相关分析(Kernel Canonical Correlation Analysis, KCCA).
Kernel典型相关分析 (一)KCCA 同样,我们可以引入Kernel函数,通过非线性的坐标变换达到之前CCA所寻求的目标.首先,假设映射$\Phi_X: x\rightarrow \Phi_X(x ...
- Jordan Lecture Note-11: 典型相关分析(Canonical Correlation Analysis, CCA).
典型相关分析 (一)引入 典型相关分析(Canonical Correlation Analysis)是研究两组变量之间相关关系的一种多元统计方法.他能够揭示出两组变量之间的内在联系. 我们知道,在一 ...
- R语言 典型相关分析
1.关键点 #典型相关分析##典型相关分析是用于分析两组随机变量之间的相关程度的一种统计方法,它能够有效地揭示两组随机变量之间的相互(线性依赖)关系#例如 研究生入学考试成绩与本科阶段一些主要课程成绩 ...
- BZOJ4817 SDOI2017 相关分析
4821: [Sdoi2017]相关分析 Time Limit: 10 Sec Memory Limit: 128 MBSec Special Judge Description Frank对天文 ...
随机推荐
- BW建模开发入门
本文档主要指导具体操作步骤,一些技术名称和描述可能在各步骤中不对应,可以忽略 一.模型建立 1.建立信息区和信息对象目录 1)进入BW工作台 2)创建信息区 输入技术名称和描述 3)创建特性和关键值的 ...
- Service Mesh 了解
是什么 Service Mesh是专用的基础设施层. 轻量级高性能网络代理. 提供安全的.快速的.可靠地服务间通讯. 与实际应用部署一起但对应用是透明的 作用 提供熔断机制(circuit-break ...
- 异常处理—Exception(二)
在上一篇中"异常处理--Exception(一)"中,跟大家简单介绍了一下Exception,也使大家充分的了解了Exception管理在一个项目中的重要性,那如何在我们的项目中处 ...
- elasticsearch 6.0.0及之后移除了一个索引允许映射多个类型的操作(Removal of mapping types)
分给线一下内容为理解错误内容,实际允许建立父子分档,只是类型改成来 join 官方demo: join datatypeedit The join datatype is a special fiel ...
- STM32的启动过程分析
对于stm32的启动过程一直心存疑惑.今天找了很多资料,进行了一个大致的分析. 1.cortex M3的复位过程(来自官方资料) 上述开机启动流程比较详细,内容较为全面,但部分步骤可以省略(红字可省略 ...
- C++使用回溯法实现N皇后问题的求解
回溯法是个很无聊的死算方法,没什么技巧,写这篇博客主要原因是以前思路不太清晰,现在突然想用回溯法解决一个问题时,无法快速把思路转换成代码. ------------------------------ ...
- JFreeChart API 说明(转)
原地址 http://blog.csdn.net/mike_caoyong/article/details/7338160 JFreeChart目前是最好的java图形解决方案,基本能够解决目前的图形 ...
- 同步机制之--java CyclicBarrier 循环栅栏
CyclicBarrier介绍一个同步辅助类,它允许一组线程互相等待,直到到达某个公共屏障点 (common barrier point).在涉及一组固定大小的线程的程序中,这些线程必须不时地互相等待 ...
- 【BZOJ】1260 [CQOI2007]涂色paint(区间dp)
题目 传送门:QWQ 分析 区间dp, 详见代码 代码 /************************************************************** Problem: ...
- 【BZOJ】2160: 拉拉队排练(Manacher)
题目 2160: 拉拉队排练 Description 艾利斯顿商学院篮球队要参加一年一度的市篮球比赛了.拉拉队是篮球比赛的一个看点,好的拉拉队往往能帮助球队增加士气,赢得最终的比赛.所以作为拉拉队队长 ...