核心蓝牙 - 禁用重复密钥过滤器会导致警告



>当我使用以下方法禁用重复键过滤时:

NSDictionary *options    = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];

构建和运行工作正常(并捕获所有广告数据包),但它总是首先产生此错误:

"核心蓝牙[警告] 正在禁用重复筛选,但对委托事件使用默认队列(主线程)"

如果我添加以下内容,我可以停止显示警告:

dispatch_queue_t centralQueue = dispatch_queue_create("central", DISPATCH_QUEUE_SERIAL);

就在我创建 CBCentralManager 的实例并将队列参数设置为 centralQueue 之前。 这是解决此问题的正确方法吗?还是有更好的方法?

谢谢

正好有一个正确的答案:

如果将 CBCentralManager 设置为在主队列上运行,则设置扫描选项以允许重复项可能会降低整体性能。 如果需要允许重复项,最好在单独的队列上运行 CBCentralManager。

dispatch_queue_t centralQueue = dispatch_queue_create("mycentralqueue", DISPATCH_QUEUE_SERIAL);
_centralManager = [[CBCentralManager alloc]initWithDelegate:self queue:centralQueue];

最新更新