【发布时间】:2015-11-02 01:12:52
【问题描述】:
我基本上想从我的 iOS 应用中搜索附近的 BLE 设备,即使应用在后台也是如此。
iOS 提供了这种方法:
//_cbcManager是CBCentralManager的对象
[_cbcManager scanForPeripheralsWithServices:nil options:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:CBCentralManagerScanOptionAllowDuplicatesKey]]
此方法将扫描所有服务(因为参数中提供了 nil)。但这在后台不起作用。当应用在后台时,iOS 需要特定的服务名称。
我基本上想扫描音频设备,阅读此页面:https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx 我已经提供了音频设备可以广播的大部分通用服务。所以现在,该方法看起来像这样:
[_cbcManager scanForPeripheralsWithServices:@[[CBUUID UUIDWithString:@"180A"], [CBUUID UUIDWithString:@"1815"], [CBUUID UUIDWithString:@"1800"], [CBUUID UUIDWithString:@"1801"], [CBUUID UUIDWithString:@"1807"], [CBUUID UUIDWithString:@"180E"], [CBUUID UUIDWithString:@"1813"], [CBUUID UUIDWithString:@"181C"]] options:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:CBCentralManagerScanOptionAllowDuplicatesKey]]
是否有每个 BLE 设备都会广播的特定/通用服务名称?
【问题讨论】:
-
大多数设备都会宣传“设备信息”0x180A,但这可能是从健身手环到 iPhone 的任何东西。许多音频设备将使用传统蓝牙,而不是 BLE,因此它们无论如何都不会出现
-
传统蓝牙?但是没有办法从iOS扫描它?? EA 框架只允许经过苹果认证的设备。
-
你让它工作了吗?请让我们知道您接受的答案。
-
这是一种限制。您无法在后台搜索所有这些,并且并非所有这些都广播蓝牙开发者页面上提到的 UUID。所以你必须忍受它......只有当设备有电池时,180F才会被广播。比如汽车音响没有电池,180F就检测不到。
标签: ios objective-c iphone core-bluetooth cbcentralmanager