Hi developers,
I am trying this code to read from 3 bluetooth beacon:
class BeaconScanner0: NSObject, CBCentralManagerDelegate {
var centralManager: CBCentralManager!
var shouldContinueScanning = true // Add a flag to control scanning
var i=0
var BeaconRSSI = [0, 0, 0]
override init() {
super.init()
centralManager = CBCentralManager(delegate: self, queue: nil)
}
func centralManagerDidUpdateState(_ central: CBCentralManager) {
if central.state == .unauthorized {
print("Bluetooth access is unauthorized. Requesting permission...")
centralManager.delegate = self
}
else if central.state == .poweredOn {
print("Bluetooth is powered on. Scanning for beacons...")
// Start scanning for all peripherals
centralManager.scanForPeripherals(withServices: nil, options: nil)
} else {
print("Bluetooth is not powered on or available.")
}
}
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String: Any], rssi: NSNumber)->[Int] {
print("BeaconRSSI: \(BeaconRSSI)")
if let name = peripheral.name {
if name.contains("BlueCharm") {
if name.contains("79") {
BeaconRSSI[0] = rssi.intValue
// i += 1
}
if name.contains("67") {
BeaconRSSI[1] = rssi.intValue
// j += 1
}
if name.contains("96") {
BeaconRSSI[2] = rssi.intValue
// k += 1
}
}
}
return BeaconRSSI
}
}
it got back the error (bug!) like below:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'String does not represent a valid UUID'
*** First throw call stack:
(0x1b361e69c 0x1ab8d7c80 0x1b2b7cdd8 0x1d8062634 0x1d80628a8 0x1d8025130 0x1d8024cd8 0x104a95140 0x104a8baa0 0x104a8b970 0x104a8bac4 0x104a8b818 0x104a8caf0 0x1057c2b34 0x1057c4690 0x104a8cb54 0x104a8cb6c 0x1057c2b34 0x1057c4690 0x104a8cc0c 0x104a8cc68 0x1057c2b34 0x1057c4690 0x104a8cd28 0x104a8cfc0 0x1057c2b34 0x1057c4690 0x104a8d064 0x104a8d61c 0x1057c2b34 0x1057c4690 0x104a8d6c4 0x104a93d98 0x104a93c74 0x1b80c709c 0x1b839a624 0x1b8ac2b68 0x1b8ac0300 0x1b8b308e8 0x1b8b30948 0x1b5794fe0 0x1b4ba9aa8 0x1b4ba9630 0x1b4bafb60 0x1b4ba8e3c 0x1b5a7e03c 0x1b35691b8 0x1b35679ac 0x1b35658ac 0x1b3565478 0x1f6abe4f8 0x1b598f360 0x1b598e99c 0x1b83a04b8 0x1b83a02fc 0x1b8010e90 0x104a9eb3c 0x104a9ec84 0x1d629ddcc)
libc++abi: terminating due to uncaught exception of type NSException
*** Assertion failure in -[CBUUID initWithString:safe:], CBUUID.m:219
could anyone help me with this problem.
Thanks beforehand.