@@ -21,6 +21,7 @@ class BluetoothManager: UIViewController, CBCentralManagerDelegate, CBPeripheral
2121 var centralManager : CBCentralManager !
2222 var peripheral : CBPeripheral !
2323 let BLEServiceUUID = CBUUID ( string: " 00110011-4455-6677-8899-aabbccddeeff " )
24+ private var rxCharacteristic : CBCharacteristic ?
2425 var callObserver = CXCallObserver ( )
2526
2627 // Singleton instance
@@ -67,6 +68,9 @@ class BluetoothManager: UIViewController, CBCentralManagerDelegate, CBPeripheral
6768
6869 // When connect to the Peripheral
6970 func centralManager( _ central: CBCentralManager , didConnect peripheral: CBPeripheral ) {
71+ self . peripheral = peripheral
72+ peripheral. delegate = self
73+ peripheral. discoverServices ( [ CBUUID ( string: " 00110011-4455-6677-8899-aabbccddeeff " ) ] )
7074 delegate? . didConnectPeripheral ( )
7175 }
7276
@@ -76,28 +80,34 @@ class BluetoothManager: UIViewController, CBCentralManagerDelegate, CBPeripheral
7680 }
7781
7882 func peripheral( _ peripheral: CBPeripheral , didDiscoverServices error: Error ? ) {
79- guard let services = peripheral. services else { return }
83+ guard let services = peripheral. services else {
84+ return
85+ }
8086 for service in services {
81- peripheral. discoverCharacteristics ( nil , for: service)
87+ peripheral. discoverCharacteristics ( [ CBUUID ( string : " 00112233-4455-6677-8899-abbccddeefff " ) ] , for: service)
8288 }
8389 }
8490
8591 func peripheral( _ peripheral: CBPeripheral , didDiscoverCharacteristicsFor service: CBService , error: Error ? ) {
86- guard let characteristics = service. characteristics else { return }
92+ guard let characteristics = service. characteristics else {
93+ return
94+ }
8795 for characteristic in characteristics {
88- print ( characteristic. uuid)
89- // Handle the available characteristics as needed
96+ if characteristic. uuid == CBUUID ( string: " 00112233-4455-6677-8899-abbccddeefff " ) {
97+ self . rxCharacteristic = characteristic
98+ peripheral. setNotifyValue ( true , for: characteristic)
99+ }
90100 }
91101 }
92102
93103 /*
94- func callObserver(_ callObserver: CXCallObserver, callChanged call: CXCall) {
95- if call.hasConnected {
96- print("Call connected")
97- } else if call.hasEnded {
98- print("Call ended")
99- }
100- }
104+ func callObserver(_ callObserver: CXCallObserver, callChanged call: CXCall) {
105+ if call.hasConnected {
106+ print("Call connected")
107+ } else if call.hasEnded {
108+ print("Call ended")
109+ }
110+ }
101111 */
102112
103113 // Read/Write/Handle the data
0 commit comments