扫描外设广播详解

2024-06-06 01:12
文章标签 广播 详解 扫描 外设

本文主要是介绍扫描外设广播详解,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

        • 扫描外设广播详解
          • 一、接口说明
          • 二、Options说明
            • 1、CBCentralManagerScanOptionAllowDuplicatesKey
            • 2、CBCentralManagerScanOptionSolicitedServiceUUIDsKey

扫描外设广播详解
一、接口说明
/*!*  @method scanForPeripheralsWithServices:options:**  @param serviceUUIDs A list of <code>CBUUID</code> objects representing the service(s) to scan for.*  @param options      An optional dictionary specifying options for the scan.**  @discussion         Starts scanning for peripherals that are advertising any of the services listed in <i>serviceUUIDs</i>. Although strongly discouraged,*                      if <i>serviceUUIDs</i> is <i>nil</i> all discovered peripherals will be returned. If the central is already scanning with different*                      <i>serviceUUIDs</i> or <i>options</i>, the provided parameters will replace them.*                      Applications that have specified the <code>bluetooth-central</code> background mode are allowed to scan while backgrounded, with two*                      caveats: the scan must specify one or more service types in <i>serviceUUIDs</i>, and the <code>CBCentralManagerScanOptionAllowDuplicatesKey</code>*                      scan option will be ignored.**  @see                centralManager:didDiscoverPeripheral:advertisementData:RSSI:*  @seealso            CBCentralManagerScanOptionAllowDuplicatesKey*    @seealso            CBCentralManagerScanOptionSolicitedServiceUUIDsKey**/
- (void)scanForPeripheralsWithServices:(nullable NSArray<CBUUID *> *)serviceUUIDs options:(nullable NSDictionary<NSString *, id> *)options;

这个方法是支持后台扫描的,前提是工程开启了后台蓝牙模式。然后两个细节:

  1. 如果是后台扫描serviceUUIDs需要至少包含一个

  2. CBCentralManagerScanOptionAllowDuplicatesKey选项将被忽略

二、Options说明
1、CBCentralManagerScanOptionAllowDuplicatesKey
/*!*  **@const** CBCentralManagerScanOptionAllowDuplicatesKey**  **@discussion** An NSNumber (Boolean) indicating that the scan should run without duplicate filtering. By default, multiple discoveries of the*              same peripheral are coalesced into a single discovery event. Specifying this option will cause a discovery event to be generated* every time the peripheral is seen, which may be many times per second. This can be useful in specific situations, such as making* a connection based on a peripheral's RSSI, but may have an adverse affect on battery-life and application performance.**  **@see**        scanForPeripheralsWithServices:options:**/

这个选项是一个bool值。缺省是false,当发现多个相同的外设时候会合并为一个事件回调。当设置为true的时候,它会将多个相同的的外设单独回调,对设备电池寿命和应用的性能会有影响。但是某些需要通过RSSI来做业务需求的,又需要持续扫描。

2、CBCentralManagerScanOptionSolicitedServiceUUIDsKey
/*!*  **@const** CBCentralManagerScanOptionSolicitedServiceUUIDsKey**  **@discussion** An NSArray of <code>CBUUID</code> objects respresenting service UUIDs. Causes the scan to also look for peripherals soliciting* any of the services contained in the list.**  **@see**        scanForPeripheralsWithServices:options:**/

这个选项是一个bool值。外设建立连接时应用程序挂起,系统会给定外设的连接警报。

这篇关于扫描外设广播详解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

idea的终端(Terminal)cmd的命令换成linux的命令详解

《idea的终端(Terminal)cmd的命令换成linux的命令详解》本文介绍IDEA配置Git的步骤:安装Git、修改终端设置并重启IDEA,强调顺序,作为个人经验分享,希望提供参考并支持脚本之... 目录一编程、设置前二、前置条件三、android设置四、设置后总结一、php设置前二、前置条件

python中列表应用和扩展性实用详解

《python中列表应用和扩展性实用详解》文章介绍了Python列表的核心特性:有序数据集合,用[]定义,元素类型可不同,支持迭代、循环、切片,可执行增删改查、排序、推导式及嵌套操作,是常用的数据处理... 目录1、列表定义2、格式3、列表是可迭代对象4、列表的常见操作总结1、列表定义是处理一组有序项目的

python使用try函数详解

《python使用try函数详解》Pythontry语句用于异常处理,支持捕获特定/多种异常、else/final子句确保资源释放,结合with语句自动清理,可自定义异常及嵌套结构,灵活应对错误场景... 目录try 函数的基本语法捕获特定异常捕获多个异常使用 else 子句使用 finally 子句捕获所

C++11范围for初始化列表auto decltype详解

《C++11范围for初始化列表autodecltype详解》C++11引入auto类型推导、decltype类型推断、统一列表初始化、范围for循环及智能指针,提升代码简洁性、类型安全与资源管理效... 目录C++11新特性1. 自动类型推导auto1.1 基本语法2. decltype3. 列表初始化3

SQL Server 中的 WITH (NOLOCK) 示例详解

《SQLServer中的WITH(NOLOCK)示例详解》SQLServer中的WITH(NOLOCK)是一种表提示,等同于READUNCOMMITTED隔离级别,允许查询在不获取共享锁的情... 目录SQL Server 中的 WITH (NOLOCK) 详解一、WITH (NOLOCK) 的本质二、工作

springboot自定义注解RateLimiter限流注解技术文档详解

《springboot自定义注解RateLimiter限流注解技术文档详解》文章介绍了限流技术的概念、作用及实现方式,通过SpringAOP拦截方法、缓存存储计数器,结合注解、枚举、异常类等核心组件,... 目录什么是限流系统架构核心组件详解1. 限流注解 (@RateLimiter)2. 限流类型枚举 (

Java Thread中join方法使用举例详解

《JavaThread中join方法使用举例详解》JavaThread中join()方法主要是让调用改方法的thread完成run方法里面的东西后,在执行join()方法后面的代码,这篇文章主要介绍... 目录前言1.join()方法的定义和作用2.join()方法的三个重载版本3.join()方法的工作原

Spring AI使用tool Calling和MCP的示例详解

《SpringAI使用toolCalling和MCP的示例详解》SpringAI1.0.0.M6引入ToolCalling与MCP协议,提升AI与工具交互的扩展性与标准化,支持信息检索、行动执行等... 目录深入探索 Spring AI聊天接口示例Function CallingMCPSTDIOSSE结束语

C语言进阶(预处理命令详解)

《C语言进阶(预处理命令详解)》文章讲解了宏定义规范、头文件包含方式及条件编译应用,强调带参宏需加括号避免计算错误,头文件应声明函数原型以便主函数调用,条件编译通过宏定义控制代码编译,适用于测试与模块... 目录1.宏定义1.1不带参宏1.2带参宏2.头文件的包含2.1头文件中的内容2.2工程结构3.条件编

PyTorch中的词嵌入层(nn.Embedding)详解与实战应用示例

《PyTorch中的词嵌入层(nn.Embedding)详解与实战应用示例》词嵌入解决NLP维度灾难,捕捉语义关系,PyTorch的nn.Embedding模块提供灵活实现,支持参数配置、预训练及变长... 目录一、词嵌入(Word Embedding)简介为什么需要词嵌入?二、PyTorch中的nn.Em