我正在尝试连接摩托罗拉环形扫描仪“R1000BT”,我面临的问题是,当我触发scanForPeripheralsWithServices:时,委托方法didDiscoverPeripheral:永远不会被调用。
我找了类似的问题,但没有人帮助过我。
到目前为止我的代码是:
#define RING_SCANNER_SERVICE_UUID @"1813"
-(void)viewDidLoad{
CBCentralManager *centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
self.centralManager = centralManager;
}
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
// Determine the state of the peripheral
if ([central state] == CBCentralManagerStatePoweredOff) {
NSLog(@"CoreBluetooth BLE hardware is powered off");
}
else if ([central state] == CBCentralManagerStatePoweredOn) {
NSLog(@"CoreBluetooth BLE hardware is powered on and ready");
NSArray *uuidArray = [NSArray arrayWithObjects:[CBUUID UUIDWithString:RING_SCANNER_SERVICE_UUID], nil];
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:CBCentralManagerScanOptionAllowDuplicatesKey];
[central scanForPeripheralsWithServices:uuidArray options:options];
}
else if ([central state] == CBCentralManagerStateUnauthorized) {
NSLog(@"CoreBluetooth BLE state is unauthorized");
}
else if ([central state] == CBCentralManagerStateUnknown) {
NSLog(@"CoreBluetooth BLE state is unknown");
}
else if ([central state] == CBCentralManagerStateUnsupported) {
NSLog(@"CoreBluetooth BLE hardware is unsupported on this platform");
}
}
- (void)centralManager:(CBCentralManager )central didDiscoverPeripheral:(CBPeripheral )peripheral advertisementData:(NSDictionary )advertisementData RSSI:(NSNumber )RSSI
{
NSString *localName = [advertisementData objectForKey:CBAdvertisementDataLocalNameKey];
if ([localName length] > 0) {
NSLog(@"Found the ring scanner: %@", localName);
[self.centralManager stopScan];
self.ringScannerPeripheral = peripheral;
peripheral.delegate = self;
[self.centralManager connectPeripheral:peripheral options:nil];
}
}
请帮我解决这个问题,我有iOS 8.1。
答案 0 :(得分:3)
根据product data,此设备是蓝牙3.0设备,它实现了串行端口协议(SPP)和人机接口设备(HID)协议。因此,iOS上的Core Bluetooth不支持它。
似乎您应该将其置于HID模式并将其与iOS设备配对作为键盘。
您尝试使用的服务UUID 0x1813
称为“扫描参数”,但这与条形码扫描无关 - 它是允许控制设备的BLE扫描速率的服务用于电源管理。