Minor changes to BT

This commit is contained in:
severin.memmishofer 2023-07-13 17:41:18 +02:00
parent 5e6c77c64d
commit 52c6083967
3 changed files with 39 additions and 2 deletions

View File

@ -31,8 +31,15 @@ extension BluetoothController: CBCentralManagerDelegate {
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
if !peripherals.contains(peripheral) {
centralManager?.connect(peripheral)
self.peripherals.append(peripheral)
self.peripheralNames.append(peripheral.name ?? "unnamed device")
}
}
func sendWantVector(data: Data) {
for peripheral in peripherals {
//peripheral.writeValue(data, for: peripheral., type: .withoutResponse)
}
}
}

32
RippleChat/File.swift Normal file
View File

@ -0,0 +1,32 @@
//
// File.swift
// RippleChat
//
// Created by Severin Memmishofer on 13.07.23.
//
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
if let error = error {
print("Error discovering services: \(error.localizedDescription)")
return
}
for service in peripheral.services ?? [] {
if service.uuid == CBUUID(string: "YourServiceUUIDHere") {
peripheral.discoverCharacteristics([CBUUID(string: "YourCharacteristicUUIDHere")], for: service)
}
}
}
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
if let error = error {
print("Error discovering characteristics: \(error.localizedDescription)")
return
}
for characteristic in service.characteristics ?? [] {
if characteristic.uuid == CBUUID(string: "YourCharacteristicUUIDHere") {
// You've found your characteristic!
}
}
}

View File

@ -24,13 +24,11 @@ struct PeeringView: View {
let WANT_msg = WantMessage(friends: dataStore.friends)
let encoded_msg = try JSONEncoder().encode(WANT_msg)
} catch {
fatalError(error.localizedDescription)
}
}) {
}
.padding()
}