@@ -21,6 +21,7 @@ class BluetoothManager: UIViewController, CBCentralManagerDelegate, CBPeripheral
21
21
var centralManager : CBCentralManager !
22
22
var peripheral : CBPeripheral !
23
23
let BLEServiceUUID = CBUUID ( string: " 00110011-4455-6677-8899-aabbccddeeff " )
24
+ private var rxCharacteristic : CBCharacteristic ?
24
25
var callObserver = CXCallObserver ( )
25
26
26
27
// Singleton instance
@@ -67,6 +68,9 @@ class BluetoothManager: UIViewController, CBCentralManagerDelegate, CBPeripheral
67
68
68
69
// When connect to the Peripheral
69
70
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 " ) ] )
70
74
delegate? . didConnectPeripheral ( )
71
75
}
72
76
@@ -76,28 +80,34 @@ class BluetoothManager: UIViewController, CBCentralManagerDelegate, CBPeripheral
76
80
}
77
81
78
82
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
+ }
80
86
for service in services {
81
- peripheral. discoverCharacteristics ( nil , for: service)
87
+ peripheral. discoverCharacteristics ( [ CBUUID ( string : " 00112233-4455-6677-8899-abbccddeefff " ) ] , for: service)
82
88
}
83
89
}
84
90
85
91
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
+ }
87
95
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
+ }
90
100
}
91
101
}
92
102
93
103
/*
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
+ }
101
111
*/
102
112
103
113
// Read/Write/Handle the data
0 commit comments