I just came on here to see if anyone could figure out why my code just won't work. In my VC (below) my thing won't go past 'Connected to your PM5'. I cannot figure out why, I don't have any errors or anything so idk? stackoverflow said that I need to add some more detail to post this because my vc is too long so I'm just writing a bunch of useless text at this point.
// If we're powered on, start scanning
func centralManagerDidUpdateState(_ central: CBCentralManager) {
print("Central state update")
if central.state != .poweredOn {
print("Central is not powered on")
} else {
print("Central scanning for", pm5ServiceUUID);
centralManager.scanForPeripherals(withServices: [pm5ServiceUUID],
options: [CBCentralManagerScanOptionAllowDuplicatesKey : true])
}
}
// Handles the result of the scan
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
// We've found it so stop scan
self.centralManager.stopScan()
// Copy the peripheral instance
self.peripheral = peripheral
self.peripheral.delegate = self
// Connect!
self.centralManager.connect(self.peripheral, options: nil)
}
// The handler if we do connect succesfully
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
if peripheral == self.peripheral {
print("Connected to your PM5")
peripheral.discoverServices([pm5ServiceUUID])
}
}
// Handles discovery event
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
if let services = peripheral.services {
for service in services {
if service.uuid == pm5ServiceUUID {
print("LED service found")
//Now kick off discovery of characteristics
peripheral.discoverCharacteristics([generalStatusUUID, additionalServiceUUID, strokeRateUUID], for: service)
return
}
}
}
}
// Handling discovery of characteristics
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
if let characteristics = service.characteristics {
for characteristic in characteristics {
if characteristic.uuid == generalStatusUUID {
print("General Status found.")
} else if characteristic.uuid == additionalServiceUUID {
print("Additional Service found.")
} else if characteristic.uuid == strokeRateUUID {
print("Stroke Rate found");
}
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
centralManager = CBCentralManager(delegate: self, queue: nil)
}
}
Any help would be appreciated. Thanks!