From 9b53e1d3e3afc7194819ae6d55f3689214db09f4 Mon Sep 17 00:00:00 2001 From: "severin.memmishofer" Date: Thu, 13 Jul 2023 18:50:28 +0200 Subject: [PATCH] Added Debug- Print Statements --- RippleChat.xcodeproj/project.pbxproj | 4 ++-- RippleChat/BTPeripheral.swift | 4 +++- RippleChat/BluetoothController.swift | 3 ++- RippleChat/Views/PeeringView.swift | 7 +++++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/RippleChat.xcodeproj/project.pbxproj b/RippleChat.xcodeproj/project.pbxproj index 3532a1c..ebf5b9a 100644 --- a/RippleChat.xcodeproj/project.pbxproj +++ b/RippleChat.xcodeproj/project.pbxproj @@ -497,7 +497,7 @@ CODE_SIGN_STYLE = Automatic; CURRENT_PROJECT_VERSION = 1; DEVELOPMENT_ASSET_PATHS = "\"RippleChat/Preview Content\""; - DEVELOPMENT_TEAM = GN2B48NJ47; + DEVELOPMENT_TEAM = B5S58UWR64; ENABLE_PREVIEWS = YES; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_KEY_NSBluetoothAlwaysUsageDescription = "Allow for bluetooth use"; @@ -512,7 +512,7 @@ "@executable_path/Frameworks", ); MARKETING_VERSION = 1.0; - PRODUCT_BUNDLE_IDENTIFIER = unibas.inetsec.RippleChat1; + PRODUCT_BUNDLE_IDENTIFIER = unibas.inetsec.RippleChat; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_VERSION = 5.0; diff --git a/RippleChat/BTPeripheral.swift b/RippleChat/BTPeripheral.swift index 4727de8..ba0d0ec 100644 --- a/RippleChat/BTPeripheral.swift +++ b/RippleChat/BTPeripheral.swift @@ -10,6 +10,7 @@ import CoreBluetooth class BluetoothPeripheral: NSObject, ObservableObject { + @Published var incomingMsg: String = "" private var peripheralManager: CBPeripheralManager? let BLE_SERVICE_UUID = CBUUID(string: "6e400001-7646-4b5b-9a50-71becce51558") @@ -63,7 +64,8 @@ extension BluetoothPeripheral: CBPeripheralManagerDelegate { do { let receivedObject = try decoder.decode(String.self, from: receivedData) // Use the received object to update your app state as needed - print(receivedObject) + print("Received Write") + self.incomingMsg = receivedObject } catch { print("Failed to decode JSON: \(error)") } diff --git a/RippleChat/BluetoothController.swift b/RippleChat/BluetoothController.swift index 20b1b26..bab3561 100644 --- a/RippleChat/BluetoothController.swift +++ b/RippleChat/BluetoothController.swift @@ -60,11 +60,12 @@ extension BluetoothController: CBCentralManagerDelegate { return } + print("Writing to Characteristic...") // Go through for characteristic in writeCharacteristics { // Go through connected peripherals and write to their characteristic for peripheral in peripherals { - peripheral.writeValue(messageData, for: characteristic, type: .withResponse) + peripheral.writeValue(messageData, for: characteristic, type: .withoutResponse) } } } diff --git a/RippleChat/Views/PeeringView.swift b/RippleChat/Views/PeeringView.swift index d780f22..f332470 100644 --- a/RippleChat/Views/PeeringView.swift +++ b/RippleChat/Views/PeeringView.swift @@ -19,16 +19,19 @@ struct PeeringView: View { } .navigationTitle("Peering") .navigationViewStyle(StackNavigationViewStyle()) + Text("Incoming msg: \(btPeripheral.incomingMsg)") Button(action: { do { let WANT_msg = WantMessage(friends: dataStore.friends) let encoded_msg = try JSONEncoder().encode(WANT_msg) - btController.writeToCharacteristics(message: String(data: encoded_msg, encoding: .utf8)!) + //btController.writeToCharacteristics(message: String(data: encoded_msg, encoding: .utf8)!) + btController.writeToCharacteristics(message: "Test") + print("Pressed Button") } catch { fatalError(error.localizedDescription) } - }) { + Text("Send WANT-Vector") } .padding() }