扫描外设广播详解

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

相关文章

HTML5的input标签的`type`属性值详解和代码示例

《HTML5的input标签的`type`属性值详解和代码示例》HTML5的`input`标签提供了多种`type`属性值,用于创建不同类型的输入控件,满足用户输入的多样化需求,从文本输入、密码输入、... 目录一、引言二、文本类输入类型2.1 text2.2 password2.3 textarea(严格

C++ move 的作用详解及陷阱最佳实践

《C++move的作用详解及陷阱最佳实践》文章详细介绍了C++中的`std::move`函数的作用,包括为什么需要它、它的本质、典型使用场景、以及一些常见陷阱和最佳实践,感兴趣的朋友跟随小编一起看... 目录C++ move 的作用详解一、一句话总结二、为什么需要 move?C++98/03 的痛点⚡C++

MySQL中between and的基本用法、范围查询示例详解

《MySQL中betweenand的基本用法、范围查询示例详解》BETWEENAND操作符在MySQL中用于选择在两个值之间的数据,包括边界值,它支持数值和日期类型,示例展示了如何使用BETWEEN... 目录一、between and语法二、使用示例2.1、betwphpeen and数值查询2.2、be

python中的flask_sqlalchemy的使用及示例详解

《python中的flask_sqlalchemy的使用及示例详解》文章主要介绍了在使用SQLAlchemy创建模型实例时,通过元类动态创建实例的方式,并说明了如何在实例化时执行__init__方法,... 目录@orm.reconstructorSQLAlchemy的回滚关联其他模型数据库基本操作将数据添

Java中ArrayList与顺序表示例详解

《Java中ArrayList与顺序表示例详解》顺序表是在计算机内存中以数组的形式保存的线性表,是指用一组地址连续的存储单元依次存储数据元素的线性结构,:本文主要介绍Java中ArrayList与... 目录前言一、Java集合框架核心接口与分类ArrayList二、顺序表数据结构中的顺序表三、常用代码手动

Python实现快速扫描目标主机的开放端口和服务

《Python实现快速扫描目标主机的开放端口和服务》这篇文章主要为大家详细介绍了如何使用Python编写一个功能强大的端口扫描器脚本,实现快速扫描目标主机的开放端口和服务,感兴趣的小伙伴可以了解下... 目录功能介绍场景应用1. 网络安全审计2. 系统管理维护3. 网络故障排查4. 合规性检查报错处理1.

JAVA线程的周期及调度机制详解

《JAVA线程的周期及调度机制详解》Java线程的生命周期包括NEW、RUNNABLE、BLOCKED、WAITING、TIMED_WAITING和TERMINATED,线程调度依赖操作系统,采用抢占... 目录Java线程的生命周期线程状态转换示例代码JAVA线程调度机制优先级设置示例注意事项JAVA线程

详解C++ 存储二进制数据容器的几种方法

《详解C++存储二进制数据容器的几种方法》本文主要介绍了详解C++存储二进制数据容器,包括std::vector、std::array、std::string、std::bitset和std::ve... 目录1.std::vector<uint8_t>(最常用)特点:适用场景:示例:2.std::arra

C++构造函数中explicit详解

《C++构造函数中explicit详解》explicit关键字用于修饰单参数构造函数或可以看作单参数的构造函数,阻止编译器进行隐式类型转换或拷贝初始化,本文就来介绍explicit的使用,感兴趣的可以... 目录1. 什么是explicit2. 隐式转换的问题3.explicit的使用示例基本用法多参数构造

Android使用java实现网络连通性检查详解

《Android使用java实现网络连通性检查详解》这篇文章主要为大家详细介绍了Android使用java实现网络连通性检查的相关知识,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录NetCheck.Java(可直接拷贝)使用示例(Activity/Fragment 内)权限要求