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

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

相关文章

SpringBoot日志级别与日志分组详解

《SpringBoot日志级别与日志分组详解》文章介绍了日志级别(ALL至OFF)及其作用,说明SpringBoot默认日志级别为INFO,可通过application.properties调整全局或... 目录日志级别1、级别内容2、调整日志级别调整默认日志级别调整指定类的日志级别项目开发过程中,利用日志

Java中的抽象类与abstract 关键字使用详解

《Java中的抽象类与abstract关键字使用详解》:本文主要介绍Java中的抽象类与abstract关键字使用详解,本文通过实例代码给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧... 目录一、抽象类的概念二、使用 abstract2.1 修饰类 => 抽象类2.2 修饰方法 => 抽象方法,没有

MySQL8 密码强度评估与配置详解

《MySQL8密码强度评估与配置详解》MySQL8默认启用密码强度插件,实施MEDIUM策略(长度8、含数字/字母/特殊字符),支持动态调整与配置文件设置,推荐使用STRONG策略并定期更新密码以提... 目录一、mysql 8 密码强度评估机制1.核心插件:validate_password2.密码策略级

从入门到精通详解Python虚拟环境完全指南

《从入门到精通详解Python虚拟环境完全指南》Python虚拟环境是一个独立的Python运行环境,它允许你为不同的项目创建隔离的Python环境,下面小编就来和大家详细介绍一下吧... 目录什么是python虚拟环境一、使用venv创建和管理虚拟环境1.1 创建虚拟环境1.2 激活虚拟环境1.3 验证虚

详解python pycharm与cmd中制表符不一样

《详解pythonpycharm与cmd中制表符不一样》本文主要介绍了pythonpycharm与cmd中制表符不一样,这个问题通常是因为PyCharm和命令行(CMD)使用的制表符(tab)的宽... 这个问题通常是因为PyCharm和命令行(CMD)使用的制表符(tab)的宽度不同导致的。在PyChar

sky-take-out项目中Redis的使用示例详解

《sky-take-out项目中Redis的使用示例详解》SpringCache是Spring的缓存抽象层,通过注解简化缓存管理,支持Redis等提供者,适用于方法结果缓存、更新和删除操作,但无法实现... 目录Spring Cache主要特性核心注解1.@Cacheable2.@CachePut3.@Ca

SpringBoot请求参数传递与接收示例详解

《SpringBoot请求参数传递与接收示例详解》本文给大家介绍SpringBoot请求参数传递与接收示例详解,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋... 目录I. 基础参数传递i.查询参数(Query Parameters)ii.路径参数(Path Va

RabbitMQ 延时队列插件安装与使用示例详解(基于 Delayed Message Plugin)

《RabbitMQ延时队列插件安装与使用示例详解(基于DelayedMessagePlugin)》本文详解RabbitMQ通过安装rabbitmq_delayed_message_exchan... 目录 一、什么是 RabbitMQ 延时队列? 二、安装前准备✅ RabbitMQ 环境要求 三、安装延时队

从基础到高级详解Python数值格式化输出的完全指南

《从基础到高级详解Python数值格式化输出的完全指南》在数据分析、金融计算和科学报告领域,数值格式化是提升可读性和专业性的关键技术,本文将深入解析Python中数值格式化输出的相关方法,感兴趣的小伙... 目录引言:数值格式化的核心价值一、基础格式化方法1.1 三种核心格式化方式对比1.2 基础格式化示例

Java中的stream流分组示例详解

《Java中的stream流分组示例详解》Java8StreamAPI以函数式风格处理集合数据,支持分组、统计等操作,可按单/多字段分组,使用String、Map.Entry或Java16record... 目录什么是stream流1、根据某个字段分组2、按多个字段分组(组合分组)1、方法一:使用 Stri