ios - BLE 后台模式 : didUpdateValueForCharacteristic not called

标签 ios bluetooth core-bluetooth bluetooth-lowenergy uibackgroundtask

我有一个自定义类(比方说,MyBLE)用作CoreBluetooth 包装器(我猜类似于 LGBluetooth )。它处理我的 BLE 配件和 iOS 设备之间的通信:

MyBLE.h

@interface MyBLE : NSObject

@property (nonatomic, strong)   CBCentralManager *central;
@property (nonatomic, strong)   CBPeripheral     *peripheral;

+ (MyBLE *)sharedInstance;

//...

@end

AppDelegate 中,我将其初始化为 MyBLE 对象,它在前台运行良好。根据 Core Bluetooth Programming Guide,我在 Info.plist 中设置了所需的条目以使用 UIBackgroundMode这样我就可以继续获取 BLE 配件发送的数据。

但是当我按下主页按钮时,Xcode 控制台不再打印出任何应该在 iOS 从 BLE 外围设备获取数据时打印的消息。该设备在进入后台模式之前已经连接到 iOS 设备(中央)。

我错过了什么吗?似乎应用程序在 3 分钟后不再从 BLE 设备获取数据。 (是的,我确实添加了 bluetooth-central)

最佳答案

在我将 MyBLE 对象的初始化从 -init: 移动到 -application:didFinishLaunchingWithOptions: 之后,它起作用了。

猜想不知何故委托(delegate)在那个时候没有被认为是初始化的。

关于ios - BLE 后台模式 : didUpdateValueForCharacteristic not called,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38483733/

相关文章:

ios - 自定义单元格内的 uitableview

android - 如何使用 SQL 数据库在 Android 中保存从 Arduino 板接收到的数据?

android - 在外部 android 应用程序中读取蓝牙消息

iOS 10 Beacon 基于位置的通知不提供主要和次要值

android - 如何设置 flutter togglebuttons 小部件的宽度

ios - TabBarController 内的 TabBarController

iOS:webview 滑动手势

objective-c - 如何从 MP MediaPlayer ViewController 显示歌曲标题、持续时间

ios - 如何在 didFinishLaunchingWithOptions AppDelegate 中使用框架函数?

ios - 在 iOS 中以编程方式删除配对的蓝牙设备