Added Debug- Print Statements

This commit is contained in:
severin.memmishofer 2023-07-13 18:50:28 +02:00
parent 8d7d6dd8ea
commit 9b53e1d3e3
4 changed files with 12 additions and 6 deletions

View File

@ -497,7 +497,7 @@
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1; CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"RippleChat/Preview Content\""; DEVELOPMENT_ASSET_PATHS = "\"RippleChat/Preview Content\"";
DEVELOPMENT_TEAM = GN2B48NJ47; DEVELOPMENT_TEAM = B5S58UWR64;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_KEY_NSBluetoothAlwaysUsageDescription = "Allow for bluetooth use"; INFOPLIST_KEY_NSBluetoothAlwaysUsageDescription = "Allow for bluetooth use";
@ -512,7 +512,7 @@
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.0; MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = unibas.inetsec.RippleChat1; PRODUCT_BUNDLE_IDENTIFIER = unibas.inetsec.RippleChat;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;

View File

@ -10,6 +10,7 @@ import CoreBluetooth
class BluetoothPeripheral: NSObject, ObservableObject { class BluetoothPeripheral: NSObject, ObservableObject {
@Published var incomingMsg: String = ""
private var peripheralManager: CBPeripheralManager? private var peripheralManager: CBPeripheralManager?
let BLE_SERVICE_UUID = CBUUID(string: "6e400001-7646-4b5b-9a50-71becce51558") let BLE_SERVICE_UUID = CBUUID(string: "6e400001-7646-4b5b-9a50-71becce51558")
@ -63,7 +64,8 @@ extension BluetoothPeripheral: CBPeripheralManagerDelegate {
do { do {
let receivedObject = try decoder.decode(String.self, from: receivedData) let receivedObject = try decoder.decode(String.self, from: receivedData)
// Use the received object to update your app state as needed // Use the received object to update your app state as needed
print(receivedObject) print("Received Write")
self.incomingMsg = receivedObject
} catch { } catch {
print("Failed to decode JSON: \(error)") print("Failed to decode JSON: \(error)")
} }

View File

@ -60,11 +60,12 @@ extension BluetoothController: CBCentralManagerDelegate {
return return
} }
print("Writing to Characteristic...")
// Go through // Go through
for characteristic in writeCharacteristics { for characteristic in writeCharacteristics {
// Go through connected peripherals and write to their characteristic // Go through connected peripherals and write to their characteristic
for peripheral in peripherals { for peripheral in peripherals {
peripheral.writeValue(messageData, for: characteristic, type: .withResponse) peripheral.writeValue(messageData, for: characteristic, type: .withoutResponse)
} }
} }
} }

View File

@ -19,16 +19,19 @@ struct PeeringView: View {
} }
.navigationTitle("Peering") .navigationTitle("Peering")
.navigationViewStyle(StackNavigationViewStyle()) .navigationViewStyle(StackNavigationViewStyle())
Text("Incoming msg: \(btPeripheral.incomingMsg)")
Button(action: { Button(action: {
do { do {
let WANT_msg = WantMessage(friends: dataStore.friends) let WANT_msg = WantMessage(friends: dataStore.friends)
let encoded_msg = try JSONEncoder().encode(WANT_msg) 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 { } catch {
fatalError(error.localizedDescription) fatalError(error.localizedDescription)
} }
}) { }) {
Text("Send WANT-Vector")
} }
.padding() .padding()
} }