蓝牙中央管理器初始化详解

2024-06-05 18:20

本文主要是介绍蓝牙中央管理器初始化详解,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

        • 蓝牙中央管理器初始化详解
          • 1、接口解释
          • 2、Options解释
            • 1、CBCentralManagerOptionShowPowerAlertKey
            • 2、CBCentralManagerOptionRestoreIdentifierKey
            • 3、CBCentralManagerOptionDeviceAccessForMedia

蓝牙中央管理器初始化详解
1、接口解释
/*!*  @method initWithDelegate:queue:options:**  @param delegate The delegate that will receive central role events.*  @param queue    The dispatch queue on which the events will be dispatched.*  @param options  An optional dictionary specifying options for the manager.**  @discussion     The initialization call. The events of the central role will be dispatched on the provided queue.*                  If <i>nil</i>, the main queue will be used.**    @seealso        CBCentralManagerOptionShowPowerAlertKey*    @seealso        CBCentralManagerOptionRestoreIdentifierKey**/
- (instancetype)initWithDelegate:(nullable id<CBCentralManagerDelegate>)delegatequeue:(nullable dispatch_queue_t)queueoptions:(nullable NSDictionary<NSString *, id> *)options NS_AVAILABLE(10_9, 7_0) NS_DESIGNATED_INITIALIZER;

delegate:CBCentralManager的回调代理

queue:CBCentralManager代理操作的所在队列,即delegate执行的所在队列。

options:其他选项,参考如下

2、Options解释
1、CBCentralManagerOptionShowPowerAlertKey
/*!*  **@const**  CBCentralManagerOptionShowPowerAlertKey**  **@discussion** An NSNumber (Boolean) indicating that the system should, if Bluetooth is powered off when <code>CBCentralManager</code> is instantiated, display* a warning dialog to the user.**  **@see** initWithDelegate:queue:options:**/

一个bool值,当蓝牙权限关闭的时候,如果CBCentralManager被初始化了,系统就是弹框提示用户蓝牙权限未开启

2、CBCentralManagerOptionRestoreIdentifierKey
/*!*  **@const**  CBCentralManagerOptionRestoreIdentifierKey**  **@discussion** An NSString containing a unique identifier (UID) for the <code>CBCentralManager</code> that is being instantiated. This UID is used* by the system to identify a specific <code>CBCentralManager</code> instance for restoration and, therefore, must remain the same for* subsequent application executions in order for the manager to be restored.**  **@see** initWithDelegate:queue:options:*  **@seealso** centralManager:willRestoreState:**/

一个string,当应用程序使用CBCentralManager与蓝牙设备进行通信时,如果设备支持(iOS 13及以上系统),可以在应用程序重启或系统重启后自动恢复与蓝牙设备的连接状态

3、CBCentralManagerOptionDeviceAccessForMedia
/*!*  **@const**  CBCentralManagerOptionDeviceAccessForMedia**  **@discussion** A Boolean representing the CBCentralManager init purpose is for DeviceAccess for media only. This will limit the functionality of this*  manager and only allow media device access without prompting the user for Bluetooth generic TCC.**  **@see** initWithDelegate:queue:options:**/

CBCentralManagerOptionDeviceAccessForMedia 是一个在iOS中用于蓝牙相关操作的选项,它用于请求访问设备的蓝牙硬件以及媒体输入和输出设备。

在iOS 13及更高版本中,当你使用CBCentralManager来管理蓝牙连接时,可以在初始化CBCentralManager时,通过options字典参数设置这个选项,以便让应用有权访问蓝牙硬件。

请注意,CBCentralManagerOptionDeviceAccessForMedia 是一个特定于iOS的选项,并不存在于其他操作系统上的Core Bluetooth框架中。因此,如果你在开发非iOS设备的应用,这个选项将不可用。

这篇关于蓝牙中央管理器初始化详解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1033817

相关文章

Python 字典 (Dictionary)使用详解

《Python字典(Dictionary)使用详解》字典是python中最重要,最常用的数据结构之一,它提供了高效的键值对存储和查找能力,:本文主要介绍Python字典(Dictionary)... 目录字典1.基本特性2.创建字典3.访问元素4.修改字典5.删除元素6.字典遍历7.字典的高级特性默认字典

MySQL 主从复制部署及验证(示例详解)

《MySQL主从复制部署及验证(示例详解)》本文介绍MySQL主从复制部署步骤及学校管理数据库创建脚本,包含表结构设计、示例数据插入和查询语句,用于验证主从同步功能,感兴趣的朋友一起看看吧... 目录mysql 主从复制部署指南部署步骤1.环境准备2. 主服务器配置3. 创建复制用户4. 获取主服务器状态5

一文详解如何使用Java获取PDF页面信息

《一文详解如何使用Java获取PDF页面信息》了解PDF页面属性是我们在处理文档、内容提取、打印设置或页面重组等任务时不可或缺的一环,下面我们就来看看如何使用Java语言获取这些信息吧... 目录引言一、安装和引入PDF处理库引入依赖二、获取 PDF 页数三、获取页面尺寸(宽高)四、获取页面旋转角度五、判断

Spring Boot中的路径变量示例详解

《SpringBoot中的路径变量示例详解》SpringBoot中PathVariable通过@PathVariable注解实现URL参数与方法参数绑定,支持多参数接收、类型转换、可选参数、默认值及... 目录一. 基本用法与参数映射1.路径定义2.参数绑定&nhttp://www.chinasem.cnbs

MySql基本查询之表的增删查改+聚合函数案例详解

《MySql基本查询之表的增删查改+聚合函数案例详解》本文详解SQL的CURD操作INSERT用于数据插入(单行/多行及冲突处理),SELECT实现数据检索(列选择、条件过滤、排序分页),UPDATE... 目录一、Create1.1 单行数据 + 全列插入1.2 多行数据 + 指定列插入1.3 插入否则更

Redis中Stream详解及应用小结

《Redis中Stream详解及应用小结》RedisStreams是Redis5.0引入的新功能,提供了一种类似于传统消息队列的机制,但具有更高的灵活性和可扩展性,本文给大家介绍Redis中Strea... 目录1. Redis Stream 概述2. Redis Stream 的基本操作2.1. XADD

Spring StateMachine实现状态机使用示例详解

《SpringStateMachine实现状态机使用示例详解》本文介绍SpringStateMachine实现状态机的步骤,包括依赖导入、枚举定义、状态转移规则配置、上下文管理及服务调用示例,重点解... 目录什么是状态机使用示例什么是状态机状态机是计算机科学中的​​核心建模工具​​,用于描述对象在其生命

Java JDK1.8 安装和环境配置教程详解

《JavaJDK1.8安装和环境配置教程详解》文章简要介绍了JDK1.8的安装流程,包括官网下载对应系统版本、安装时选择非系统盘路径、配置JAVA_HOME、CLASSPATH和Path环境变量,... 目录1.下载JDK2.安装JDK3.配置环境变量4.检验JDK官网下载地址:Java Downloads

使用Python删除Excel中的行列和单元格示例详解

《使用Python删除Excel中的行列和单元格示例详解》在处理Excel数据时,删除不需要的行、列或单元格是一项常见且必要的操作,本文将使用Python脚本实现对Excel表格的高效自动化处理,感兴... 目录开发环境准备使用 python 删除 Excphpel 表格中的行删除特定行删除空白行删除含指定

MySQL中的LENGTH()函数用法详解与实例分析

《MySQL中的LENGTH()函数用法详解与实例分析》MySQLLENGTH()函数用于计算字符串的字节长度,区别于CHAR_LENGTH()的字符长度,适用于多字节字符集(如UTF-8)的数据验证... 目录1. LENGTH()函数的基本语法2. LENGTH()函数的返回值2.1 示例1:计算字符串