- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
解释:
我正在使用核心蓝牙框架连接到 BTLE 外围设备,将外围设备标识符保存在数据库中。
同时,我将外围设备保存在一个数组中以处理与外围设备的重新连接。
但是,当用户手动退出应用程序时,我的数组变为空。
因此我将无法再次重新连接这些外围设备。
现在,我的数据库中有外围设备标识符。
我已经阅读了它,发现有一个委托(delegate)方法
- (NSArray<CBPeripheral *> *)retrievePeripheralsWithIdentifiers:(NSArray<NSUUID *> *)identifiers NS_AVAILABLE(NA, 7_0)
要获取外围设备,但它没有任何返回。
我如何才能再次获取外围设备?
我也检查了上面的文件。因为他们提到了重新连接到外围设备的方法
Retrieving a List of Known Peripherals
The first time you discover a peripheral, the system generates an identifier (a UUID, represented by an NSUUID object) to identify the peripheral. You can then store this identifier (using, for instance, the resources of the NSUserDefaults class), and later use it to try to reconnect to the peripheral using the retrievePeripheralsWithIdentifiers: method of the CBCentralManager class. The following describes one way to use this method to reconnect to a peripheral you’ve previously connected to.
When your app launches, call the retrievePeripheralsWithIdentifiers: method, passing in an array containing the identifiers of the peripherals you’ve previously discovered and connected to (and whose identifiers you have saved), like this:
knownPeripherals =
[myCentralManager retrievePeripheralsWithIdentifiers:savedIdentifiers];
The central manager tries to match the identifiers you provided to the identifiers of previously discovered peripherals and returns the results as an array of CBPeripheral objects. If no matches are found, the array is empty and you should try one of the other two reconnection options. If the array is not empty, let the user select (in the UI) which peripheral to try to reconnect to.
When the user selects a peripheral, try to connect to it by calling the connectPeripheral:options: method of the CBCentralManager class. If the peripheral device is still available to be connected to, the central manager calls the centralManager:didConnectPeripheral: method of its delegate object and the peripheral device is successfully reconnected.
Note: A peripheral device may not be available to be connected to for a few reasons. For instance, the device may not be in the vicinity of the central. In addition, some Bluetooth low energy devices use a random device address that changes periodically. Therefore, even if the device is nearby, the address of the device may have changed since the last time it was discovered by the system, in which case the CBPeripheral object you are trying to connect to doesn’t correspond to the actual peripheral device. If you cannot reconnect to the peripheral because its address has changed, you must rediscover it using the scanForPeripheralsWithServices:options: method.
最佳答案
在应用程序启动时,我会发现所有外围设备,然后将发现的外围设备与存储在数据库中的外围设备标识符进行比较。
将发现的外设与外设进行比对后,即可进行所需外设的连接。
关于ios - 当用户从后台手动退出应用程序时如何检索 BLE 外设?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39930889/
我正在开发一个使用 BLE Android 到 iOS 的聊天应用程序,现在我正在使用下面两个库作为引用 https://github.com/izumin5210/Bletia https://gi
我正在从 HCI 套接字接收 EVT_LE_ADVERTISING_REPORT。我想区分 BLE 信标和普通 BLE 设备(解析设备名称等)我有点困惑是否所有 BLE 设备都会发出信标或者它们是不同
我正在从 HCI 套接字接收 EVT_LE_ADVERTISING_REPORT。我想区分 BLE 信标和普通 BLE 设备(解析设备名称等)我有点困惑是否所有 BLE 设备都会发出信标或者它们是不同
我在我的 iOS 应用程序项目中使用核心蓝牙框架。我有以下关于蓝牙低功耗的问题 - iOS 中单个中央设备是否可以连接多个外围设备? 多个中央设备可以与单个外围设备连接吗? 单个 iOS 设备可以同时
我正在创建一个 iOS 和一个 Android 应用程序,它们从蓝牙传感器读取一些数据并将它们保存在数据库中。 即使应用程序终止,我也想提供保存传感器数据的能力。 仅供引用。当应用程序在后台时,我已经
我正在使用核心蓝牙框架并扫描一些设备,例如 micromax A250、micromax A116、samsung grand neo、HTC 610 和 ipod 5s,然后我无法扫描 samsun
这个任务的目的是通过BLE设备连接iPhone的BLE,访问iphone的ANCS。请注意,iPhone 中没有安装应用程序来打开 iPhone 的 BLE。那么,如果我们从 iPhone 设置中启用
我在为我的 BLE 设备开发安卓软件时遇到了问题。我的软件可以找到我的设备和 GATT 服务,但在我的服务中找不到任何特征。 我检查了 android-sdk-4.4.2 源码,找到了一些代码。 ht
有什么方法可以从 BleExplr、LightBlue 等通用 BLE 扫描应用程序中隐藏 BLE 设备? 最佳答案 您可以配置外围设备以使用服务请求。在这种模式下,中央为它们提供服务和外设扫描 -
我有 3 个组件。 Activity1 有连接和断开 BLE 连接的按钮 Activity2 需要从 BLE 设备获取数据。 Service 所有连接逻辑(如 getRemoteDevice()、co
我有一个 BLE 设备,它在通过相当标准的用户界面(点击 UITableView 中显示的设备条目)选择后连接到 iOS 设备。 连接非常简单 - 一些内部处理,然后调用 CBCentralManag
我正在尝试使用 Meteor 和这个 Cordova 插件 - https://github.com/don/cordova-plugin-ble-central - 使用 meteor add co
我坚持在 Android Lollipop 智能手机和 BLE 设备(带有 BLE 模块的 TI 实验板)之间实现连接。我使用以下调用进行连接: device.connectGatt(context,
我正在使用 react-native-ble-plx 在我的应用程序中实现蓝牙 蓝牙扫描工作正常,但它在 android 中包含重复项,而在 iOS 中工作正常,因为 allowDuplicates
我正在尝试在我的 Windows 笔记本电脑上设置一个基于 Nodejs 的演示,并使用额外的 BLE 适配器将我的笔记本电脑连接到另一个 BLE 设备 (Anki Overdrive)。我在互联网上
我正在研究基于 Android 的 BLE 接近感应功能,需要一些信息。目前我看到没有适用于 android 的 BLE 信标制造商。到目前为止,我为 iPhone 找到了 2 个。1) http:/
我正在使用 cordova 和 BLE 插件开发一个应用程序。我想通过 BLE 根据硬编码的已知 device.name 自动连接到 ESP32,而无需用户按下连接按钮。 我的想法是: 在设备准备就绪
我正在尝试实现从/向蓝牙设备接收和发送消息的模块。 我一直在寻找可以通过蓝牙搜索、连接和发送消息的 NuGet 包,但找不到适用于 Linux 的任何东西。 我正在使用 .NET Core 2.1 和
我正在尝试寻找一种方法来了解如何在 iOS 中获取 BLE mac??? 这将适用于所有 BLE,不会存在制造商依赖性。我们正在寻找扫描时间的解决方案。我可以在扫描时间内区分 BLE 吗? 如果获取M
我已阅读技术规范并试图了解为什么 BLE 4.2 比 BLE 4.1 更快? 我们能否发送大于 20 字节的数据包或者连接间隔是否更快? 我想了解是什么让 BLE 4.2 更快。 最佳答案 与早期相比
我是一名优秀的程序员,十分优秀!