-
Notifications
You must be signed in to change notification settings - Fork 46
Open
Description
Issue
When I scan for all peripherals without specifying a service like the following, I get a certain number of devices that support service 180A (Device Information), as evidenced by the logs printed by discoverServices:
RZBUserInteraction.setEnabled(true)
RZBUserInteraction.setTimeout(5)
var tags = [Tag]()
central.scanForPeripherals(withServices: nil, options: nil) { (scanInfo, scanError) in
if let error = scanError {
if let bluetoothError = RZBluetoothError(rawValue: UInt(error._code)) {
if bluetoothError == .timeoutError {
completion(.success(tags))
} else {
print("Failed to scan for peripherals because \(String(describing: bluetoothError))")
}
} else {
print("Failed to scan for peripherals because \(String(describing: error))")
}
} else if let info = scanInfo {
let peripheral = info.peripheral
if(!tags.contains(where: { tag -> Bool in
tag.uuid == peripheral.identifier.uuidString
})) {
tags.append(Tag(
id: nil,
uuid: peripheral.identifier.uuidString,
name: peripheral.name,
RSSI: info.rssi.intValue
))
peripheral.discoverServiceUUIDs([CBUUID(string: "180A")], completion: { error in
if let error = error {
print("Failed to discover services for \(peripheral.identifier.uuidString) because \(String(describing: error))")
} else {
print("Peripheral \(peripheral.identifier.uuidString) supports 180A")
}
})
}
}
}But if I scan specifically for peripherals that advertise that 180A service, I get zero device, as evidenced by the fact that the breakpoint I place on let peripheral = info.peripheral is never triggered.
RZBUserInteraction.setEnabled(true)
RZBUserInteraction.setTimeout(5)
var tags = [Tag]()
central.scanForPeripherals(withServices: [CBUUID(string: "180A")], options: nil) { (scanInfo, scanError) in
if let error = scanError {
if let bluetoothError = RZBluetoothError(rawValue: UInt(error._code)) {
if bluetoothError == .timeoutError {
completion(.success(tags))
} else {
print("Failed to scan for peripherals because \(String(describing: bluetoothError))")
}
} else {
print("Failed to scan for peripherals because \(String(describing: error))")
}
} else if let info = scanInfo {
let peripheral = info.peripheral
if(!tags.contains(where: { tag -> Bool in
tag.uuid == peripheral.identifier.uuidString
})) {
tags.append(Tag(
id: nil,
uuid: peripheral.identifier.uuidString,
name: peripheral.name,
RSSI: info.rssi.intValue
))
peripheral.discoverServiceUUIDs([CBUUID(string: "180A")], completion: { error in
if let error = error {
print("Failed to discover services for \(peripheral.identifier.uuidString) because \(String(describing: error))")
} else {
print("Peripheral \(peripheral.identifier.uuidString) supports 180A")
}
})
}
}
}Am I forgetting something?
Metadata
Metadata
Assignees
Labels
No labels