From d111a9537ff809f33d99b4d5d24997e5e2379496 Mon Sep 17 00:00:00 2001 From: jack Date: Thu, 10 Jul 2025 12:29:24 +0200 Subject: [PATCH 1/4] Add extensive Bluetooth debug logging to diagnose peer discovery issues - Add debug logs to centralManagerDidUpdateState and peripheralManagerDidUpdateState - Add logging to startServices to show manager states at initialization - Add logging when peripherals are discovered with RSSI values - Temporarily lower RSSI threshold from -90 to -100 dBm for testing - Add logging to show when scanning starts and if it's blocked --- bitchat.xcodeproj/project.pbxproj | 11 ++++------ bitchat/Services/BluetoothMeshService.swift | 24 ++++++++++++++++++++- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/bitchat.xcodeproj/project.pbxproj b/bitchat.xcodeproj/project.pbxproj index 9ee9abe3..9e4130c7 100644 --- a/bitchat.xcodeproj/project.pbxproj +++ b/bitchat.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 54; + objectVersion = 63; objects = { /* Begin PBXBuildFile section */ @@ -17,7 +17,6 @@ 2E71E320EA921498C57E023B /* BitchatMessageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FA8FF26ABDC1C642A8C7AE5 /* BitchatMessageTests.swift */; }; 31D147471B9F4E2815352DDA /* LinkPreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AC141774F6671FCDC347DC7 /* LinkPreviewView.swift */; }; 4274B6016F755946FBF2513E /* MessageRetentionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A85BFDDE65B4CD8BDF6DDB /* MessageRetentionService.swift */; }; - 46E1E1013CC18AB66105DB27 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 95F16C3A4A5621C74461D8D3 /* LaunchScreen.storyboard */; }; 4B747085D07A1BCE0F5BA612 /* BinaryProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2136C3E22D02D4A8DBE7EAB /* BinaryProtocol.swift */; }; 4E778E5A414571ACAC2A0F01 /* MessageRetentionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A85BFDDE65B4CD8BDF6DDB /* MessageRetentionService.swift */; }; 5D95F2BFBE257A1225998389 /* BatteryOptimizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED176FF3B274E35C2D827894 /* BatteryOptimizer.swift */; }; @@ -112,14 +111,14 @@ 3FA8FF26ABDC1C642A8C7AE5 /* BitchatMessageTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BitchatMessageTests.swift; sourceTree = ""; }; 527EB217EFDFAD4CF1C91F07 /* bitchat.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = bitchat.entitlements; sourceTree = ""; }; 53D535D9CE0B875F47402290 /* BinaryProtocolTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinaryProtocolTests.swift; sourceTree = ""; }; - 61F92EBA29C47C0FCC482F1F /* bitchatShareExtension.appex */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "wrapper.app-extension"; path = bitchatShareExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; }; + 61F92EBA29C47C0FCC482F1F /* bitchatShareExtension.appex */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "wrapper.extensionkit-extension"; path = bitchatShareExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; }; 67A85BFDDE65B4CD8BDF6DDB /* MessageRetentionService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageRetentionService.swift; sourceTree = ""; }; 6DC1563390A15C042D059CF9 /* EncryptionService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncryptionService.swift; sourceTree = ""; }; 763E0DBA9492A654FC0CDCB9 /* AppInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppInfoView.swift; sourceTree = ""; }; 8DE9CDF66D4E52D268851048 /* MessagePaddingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagePaddingTests.swift; sourceTree = ""; }; - 8F3A7C058C2C8E1A06C8CF8B /* bitchat_macOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = bitchat_macOS.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 8F3A7C058C2C8E1A06C8CF8B /* bitchat_macOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; name = bitchat_macOS.app; path = bitchat.app; sourceTree = BUILT_PRODUCTS_DIR; }; 95F16C3A4A5621C74461D8D3 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; - 96D0D41CA19EE5A772AA8434 /* bitchat_iOS.app */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.application; path = bitchat_iOS.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 96D0D41CA19EE5A772AA8434 /* bitchat_iOS.app */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.application; name = bitchat_iOS.app; path = bitchat.app; sourceTree = BUILT_PRODUCTS_DIR; }; 9AC141774F6671FCDC347DC7 /* LinkPreviewView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkPreviewView.swift; sourceTree = ""; }; A08E03AA0C63E97C91749AEC /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; A2136C3E22D02D4A8DBE7EAB /* BinaryProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinaryProtocol.swift; sourceTree = ""; }; @@ -384,7 +383,6 @@ ); mainGroup = 18198ED912AAF495D8AF7763; minimizedProjectReferenceProxies = 1; - preferredProjectObjectVersion = 54; projectDirPath = ""; projectRoot = ""; targets = ( @@ -403,7 +401,6 @@ buildActionMask = 2147483647; files = ( 7DD72D928FF9DD3CA81B46B0 /* Assets.xcassets in Resources */, - 46E1E1013CC18AB66105DB27 /* LaunchScreen.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/bitchat/Services/BluetoothMeshService.swift b/bitchat/Services/BluetoothMeshService.swift index 8ea9dbbc..0efca2be 100644 --- a/bitchat/Services/BluetoothMeshService.swift +++ b/bitchat/Services/BluetoothMeshService.swift @@ -260,11 +260,13 @@ class BluetoothMeshService: NSObject { var randomBytes = [UInt8](repeating: 0, count: 4) _ = SecRandomCopyBytes(kSecRandomDefault, 4, &randomBytes) self.myPeerID = randomBytes.map { String(format: "%02x", $0) }.joined() + print("[BLUETOOTH DEBUG] BluetoothMeshService initializing with peer ID: \(self.myPeerID)") super.init() centralManager = CBCentralManager(delegate: self, queue: nil) peripheralManager = CBPeripheralManager(delegate: self, queue: nil) + print("[BLUETOOTH DEBUG] Central and Peripheral managers created") // Start bloom filter reset timer (reset every 5 minutes) bloomFilterResetTimer = Timer.scheduledTimer(withTimeInterval: 300.0, repeats: true) { [weak self] _ in @@ -362,13 +364,22 @@ class BluetoothMeshService: NSObject { func startServices() { // Starting services + print("[BLUETOOTH DEBUG] startServices called") + print("[BLUETOOTH DEBUG] Central state: \(centralManager?.state.rawValue ?? -1), Peripheral state: \(peripheralManager?.state.rawValue ?? -1)") + // Start both central and peripheral services if centralManager?.state == .poweredOn { + print("[BLUETOOTH DEBUG] Central already powered on, starting scan") startScanning() + } else { + print("[BLUETOOTH DEBUG] Central not yet powered on") } if peripheralManager?.state == .poweredOn { + print("[BLUETOOTH DEBUG] Peripheral already powered on, setting up") setupPeripheral() startAdvertising() + } else { + print("[BLUETOOTH DEBUG] Peripheral not yet powered on") } // Send initial announces after services are ready @@ -430,7 +441,9 @@ class BluetoothMeshService: NSObject { } func startScanning() { + print("[BLUETOOTH DEBUG] startScanning called, central state: \(centralManager?.state.rawValue ?? -1)") guard centralManager?.state == .poweredOn else { + print("[BLUETOOTH DEBUG] Cannot start scanning, central not powered on") return } @@ -2243,7 +2256,9 @@ class BluetoothMeshService: NSObject { extension BluetoothMeshService: CBCentralManagerDelegate { func centralManagerDidUpdateState(_ central: CBCentralManager) { // Central manager state updated + print("[BLUETOOTH DEBUG] Central manager state changed to: \(central.state.rawValue) (poweredOn = 5)") if central.state == .poweredOn { + print("[BLUETOOTH DEBUG] Central powered on, starting scan") startScanning() // Send announces when central manager is ready @@ -2256,9 +2271,14 @@ extension BluetoothMeshService: CBCentralManagerDelegate { func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) { // Optimize for 300m range - only connect to strong enough signals let rssiValue = RSSI.intValue + print("[BLUETOOTH DEBUG] Discovered peripheral: \(peripheral.name ?? "Unknown") ID: \(peripheral.identifier) RSSI: \(rssiValue)") // Filter out very weak signals (below -90 dBm) to save battery - guard rssiValue > -90 else { return } + // TEMPORARILY LOWERED FOR DEBUGGING + guard rssiValue > -100 else { + print("[BLUETOOTH DEBUG] Ignoring peripheral due to very weak signal") + return + } // Throttle RSSI updates to save CPU let peripheralID = peripheral.identifier.uuidString @@ -2582,8 +2602,10 @@ extension BluetoothMeshService: CBPeripheralDelegate { extension BluetoothMeshService: CBPeripheralManagerDelegate { func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) { // Peripheral manager state updated + print("[BLUETOOTH DEBUG] Peripheral manager state changed to: \(peripheral.state.rawValue) (poweredOn = 5)") switch peripheral.state { case .poweredOn: + print("[BLUETOOTH DEBUG] Peripheral powered on, setting up and advertising") setupPeripheral() startAdvertising() From 7e78d0fe87180ec4ad658e0c6554bb40bc3bcec2 Mon Sep 17 00:00:00 2001 From: jack Date: Thu, 10 Jul 2025 12:39:58 +0200 Subject: [PATCH 2/4] Add more Bluetooth debugging and disable scan duty cycling - Add better state descriptions for both central and peripheral managers - Add logging when setting up peripheral and adding service - Temporarily disable scan duty cycling to ensure continuous scanning - Add service UUID logging during peripheral setup This should help identify: 1. Why Mac shows 'unsupported' state for Bluetooth 2. Whether services are being added successfully 3. If advertising is actually starting --- bitchat/Services/BluetoothMeshService.swift | 72 +++++++++++++++++++-- 1 file changed, 65 insertions(+), 7 deletions(-) diff --git a/bitchat/Services/BluetoothMeshService.swift b/bitchat/Services/BluetoothMeshService.swift index 0efca2be..979678e2 100644 --- a/bitchat/Services/BluetoothMeshService.swift +++ b/bitchat/Services/BluetoothMeshService.swift @@ -80,8 +80,8 @@ class BluetoothMeshService: NSObject { // Battery and range optimizations private var scanDutyCycleTimer: Timer? private var isActivelyScanning = true - private var activeScanDuration: TimeInterval = 2.0 // Scan actively for 2 seconds - will be adjusted based on battery - private var scanPauseDuration: TimeInterval = 3.0 // Pause for 3 seconds - will be adjusted based on battery + private var activeScanDuration: TimeInterval = 10.0 // Increased to 10 seconds for debugging - will be adjusted based on battery + private var scanPauseDuration: TimeInterval = 2.0 // Reduced to 2 seconds for debugging - will be adjusted based on battery private var lastRSSIUpdate: [String: Date] = [:] // Throttle RSSI updates private var batteryMonitorTimer: Timer? private var currentBatteryLevel: Float = 1.0 // Default to full battery @@ -422,7 +422,9 @@ class BluetoothMeshService: NSObject { } func startAdvertising() { + print("[BLUETOOTH DEBUG] startAdvertising called, peripheral state: \(peripheralManager?.state.rawValue ?? -1)") guard peripheralManager?.state == .poweredOn else { + print("[BLUETOOTH DEBUG] Cannot start advertising, peripheral not powered on") return } @@ -436,6 +438,7 @@ class BluetoothMeshService: NSObject { CBAdvertisementDataLocalNameKey: myPeerID ] + print("[BLUETOOTH DEBUG] Starting advertising with service UUID: \(BluetoothMeshService.serviceUUID), peerID: \(myPeerID)") isAdvertising = true peripheralManager?.startAdvertising(advertisementData) } @@ -452,16 +455,19 @@ class BluetoothMeshService: NSObject { CBCentralManagerScanOptionAllowDuplicatesKey: true ] + print("[BLUETOOTH DEBUG] Starting scan for peripherals with service UUID: \(BluetoothMeshService.serviceUUID)") centralManager?.scanForPeripherals( withServices: [BluetoothMeshService.serviceUUID], options: scanOptions ) + print("[BLUETOOTH DEBUG] Scan started successfully") // Update scan parameters based on battery before starting updateScanParametersForBattery() // Implement scan duty cycling for battery efficiency - scheduleScanDutyCycle() + // TEMPORARILY DISABLED FOR DEBUGGING + // scheduleScanDutyCycle() } private func scheduleScanDutyCycle() { @@ -475,6 +481,7 @@ class BluetoothMeshService: NSObject { if self.isActivelyScanning { // Pause scanning to save battery + print("[BLUETOOTH DEBUG] Pausing scan after \(self.activeScanDuration) seconds") self.centralManager?.stopScan() self.isActivelyScanning = false @@ -482,6 +489,7 @@ class BluetoothMeshService: NSObject { DispatchQueue.main.asyncAfter(deadline: .now() + self.scanPauseDuration) { [weak self] in guard let self = self else { return } if self.centralManager?.state == .poweredOn { + print("[BLUETOOTH DEBUG] Resuming scan after \(self.scanPauseDuration) seconds pause") self.centralManager?.scanForPeripherals( withServices: [BluetoothMeshService.serviceUUID], options: [CBCentralManagerScanOptionAllowDuplicatesKey: true] @@ -494,6 +502,7 @@ class BluetoothMeshService: NSObject { } private func setupPeripheral() { + print("[BLUETOOTH DEBUG] Setting up peripheral with service UUID: \(BluetoothMeshService.serviceUUID)") let characteristic = CBMutableCharacteristic( type: BluetoothMeshService.characteristicUUID, properties: [.read, .write, .writeWithoutResponse, .notify], @@ -504,6 +513,7 @@ class BluetoothMeshService: NSObject { let service = CBMutableService(type: BluetoothMeshService.serviceUUID, primary: true) service.characteristics = [characteristic] + print("[BLUETOOTH DEBUG] Adding service to peripheral manager") peripheralManager?.add(service) self.characteristic = characteristic } @@ -2256,8 +2266,26 @@ class BluetoothMeshService: NSObject { extension BluetoothMeshService: CBCentralManagerDelegate { func centralManagerDidUpdateState(_ central: CBCentralManager) { // Central manager state updated - print("[BLUETOOTH DEBUG] Central manager state changed to: \(central.state.rawValue) (poweredOn = 5)") - if central.state == .poweredOn { + let stateString: String + switch central.state { + case .unknown: stateString = "unknown(0)" + case .resetting: stateString = "resetting(1)" + case .unsupported: stateString = "unsupported(2)" + case .unauthorized: stateString = "unauthorized(3)" + case .poweredOff: stateString = "poweredOff(4)" + case .poweredOn: stateString = "poweredOn(5)" + @unknown default: stateString = "unknown state(\(central.state.rawValue))" + } + + print("[BLUETOOTH DEBUG] Central manager state changed to: \(stateString)") + + if central.state == .unsupported { + print("[BLUETOOTH DEBUG] Bluetooth is not supported on this device") + } else if central.state == .unauthorized { + print("[BLUETOOTH DEBUG] Bluetooth is unauthorized. Check app permissions in Settings") + } else if central.state == .poweredOff { + print("[BLUETOOTH DEBUG] Bluetooth is powered off. Please turn on Bluetooth") + } else if central.state == .poweredOn { print("[BLUETOOTH DEBUG] Central powered on, starting scan") startScanning() @@ -2602,8 +2630,26 @@ extension BluetoothMeshService: CBPeripheralDelegate { extension BluetoothMeshService: CBPeripheralManagerDelegate { func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) { // Peripheral manager state updated - print("[BLUETOOTH DEBUG] Peripheral manager state changed to: \(peripheral.state.rawValue) (poweredOn = 5)") + let stateString: String switch peripheral.state { + case .unknown: stateString = "unknown(0)" + case .resetting: stateString = "resetting(1)" + case .unsupported: stateString = "unsupported(2)" + case .unauthorized: stateString = "unauthorized(3)" + case .poweredOff: stateString = "poweredOff(4)" + case .poweredOn: stateString = "poweredOn(5)" + @unknown default: stateString = "unknown state(\(peripheral.state.rawValue))" + } + + print("[BLUETOOTH DEBUG] Peripheral manager state changed to: \(stateString)") + + switch peripheral.state { + case .unsupported: + print("[BLUETOOTH DEBUG] Bluetooth is not supported on this device") + case .unauthorized: + print("[BLUETOOTH DEBUG] Bluetooth is unauthorized. Check app permissions in Settings") + case .poweredOff: + print("[BLUETOOTH DEBUG] Bluetooth is powered off. Please turn on Bluetooth") case .poweredOn: print("[BLUETOOTH DEBUG] Peripheral powered on, setting up and advertising") setupPeripheral() @@ -2619,7 +2665,19 @@ extension BluetoothMeshService: CBPeripheralManagerDelegate { } func peripheralManager(_ peripheral: CBPeripheralManager, didAdd service: CBService, error: Error?) { - // Handle service addition if needed + if let error = error { + print("[BLUETOOTH DEBUG] Failed to add service: \(error.localizedDescription)") + } else { + print("[BLUETOOTH DEBUG] Service added successfully: \(service.uuid)") + } + } + + func peripheralManagerDidStartAdvertising(_ peripheral: CBPeripheralManager, error: Error?) { + if let error = error { + print("[BLUETOOTH DEBUG] Failed to start advertising: \(error.localizedDescription)") + } else { + print("[BLUETOOTH DEBUG] Advertising started successfully") + } } func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveWrite requests: [CBATTRequest]) { From c6d74b75745bd681b487bc2ab42e58714bdce521 Mon Sep 17 00:00:00 2001 From: jack Date: Thu, 10 Jul 2025 12:45:00 +0200 Subject: [PATCH 3/4] Fix macOS Bluetooth permissions by adding proper entitlements - Create separate bitchat-macOS.entitlements file with com.apple.security.device.bluetooth - Update project.yml to use the macOS-specific entitlements for the macOS target - Regenerate Xcode project with proper entitlements configuration This fixes the 'Bluetooth unsupported' issue on macOS which was caused by missing device.bluetooth entitlement required for sandboxed apps --- bitchat.xcodeproj/project.pbxproj | 17 +++++++++++------ bitchat/Info.plist | 20 -------------------- bitchat/bitchat-macOS.entitlements | 14 ++++++++++++++ project.yml | 2 +- 4 files changed, 26 insertions(+), 27 deletions(-) create mode 100644 bitchat/bitchat-macOS.entitlements diff --git a/bitchat.xcodeproj/project.pbxproj b/bitchat.xcodeproj/project.pbxproj index 9e4130c7..5a6a1e56 100644 --- a/bitchat.xcodeproj/project.pbxproj +++ b/bitchat.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 63; + objectVersion = 54; objects = { /* Begin PBXBuildFile section */ @@ -17,6 +17,7 @@ 2E71E320EA921498C57E023B /* BitchatMessageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FA8FF26ABDC1C642A8C7AE5 /* BitchatMessageTests.swift */; }; 31D147471B9F4E2815352DDA /* LinkPreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AC141774F6671FCDC347DC7 /* LinkPreviewView.swift */; }; 4274B6016F755946FBF2513E /* MessageRetentionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A85BFDDE65B4CD8BDF6DDB /* MessageRetentionService.swift */; }; + 46E1E1013CC18AB66105DB27 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 95F16C3A4A5621C74461D8D3 /* LaunchScreen.storyboard */; }; 4B747085D07A1BCE0F5BA612 /* BinaryProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2136C3E22D02D4A8DBE7EAB /* BinaryProtocol.swift */; }; 4E778E5A414571ACAC2A0F01 /* MessageRetentionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A85BFDDE65B4CD8BDF6DDB /* MessageRetentionService.swift */; }; 5D95F2BFBE257A1225998389 /* BatteryOptimizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED176FF3B274E35C2D827894 /* BatteryOptimizer.swift */; }; @@ -111,14 +112,14 @@ 3FA8FF26ABDC1C642A8C7AE5 /* BitchatMessageTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BitchatMessageTests.swift; sourceTree = ""; }; 527EB217EFDFAD4CF1C91F07 /* bitchat.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = bitchat.entitlements; sourceTree = ""; }; 53D535D9CE0B875F47402290 /* BinaryProtocolTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinaryProtocolTests.swift; sourceTree = ""; }; - 61F92EBA29C47C0FCC482F1F /* bitchatShareExtension.appex */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "wrapper.extensionkit-extension"; path = bitchatShareExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; }; + 61F92EBA29C47C0FCC482F1F /* bitchatShareExtension.appex */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "wrapper.app-extension"; path = bitchatShareExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; }; 67A85BFDDE65B4CD8BDF6DDB /* MessageRetentionService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageRetentionService.swift; sourceTree = ""; }; 6DC1563390A15C042D059CF9 /* EncryptionService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncryptionService.swift; sourceTree = ""; }; 763E0DBA9492A654FC0CDCB9 /* AppInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppInfoView.swift; sourceTree = ""; }; 8DE9CDF66D4E52D268851048 /* MessagePaddingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagePaddingTests.swift; sourceTree = ""; }; - 8F3A7C058C2C8E1A06C8CF8B /* bitchat_macOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; name = bitchat_macOS.app; path = bitchat.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 8F3A7C058C2C8E1A06C8CF8B /* bitchat_macOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = bitchat_macOS.app; sourceTree = BUILT_PRODUCTS_DIR; }; 95F16C3A4A5621C74461D8D3 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; - 96D0D41CA19EE5A772AA8434 /* bitchat_iOS.app */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.application; name = bitchat_iOS.app; path = bitchat.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 96D0D41CA19EE5A772AA8434 /* bitchat_iOS.app */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.application; path = bitchat_iOS.app; sourceTree = BUILT_PRODUCTS_DIR; }; 9AC141774F6671FCDC347DC7 /* LinkPreviewView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkPreviewView.swift; sourceTree = ""; }; A08E03AA0C63E97C91749AEC /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; A2136C3E22D02D4A8DBE7EAB /* BinaryProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinaryProtocol.swift; sourceTree = ""; }; @@ -132,6 +133,7 @@ EA706D8E5097785414646A8E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; ED176FF3B274E35C2D827894 /* BatteryOptimizer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BatteryOptimizer.swift; sourceTree = ""; }; EF625BB3AD919322C01A46B2 /* BitchatApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BitchatApp.swift; sourceTree = ""; }; + FF7AF93D874001FBD94C8306 /* bitchat-macOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "bitchat-macOS.entitlements"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXGroup section */ @@ -149,6 +151,7 @@ isa = PBXGroup; children = ( 3A69677D382F1C3D5ED03F7D /* Assets.xcassets */, + FF7AF93D874001FBD94C8306 /* bitchat-macOS.entitlements */, 527EB217EFDFAD4CF1C91F07 /* bitchat.entitlements */, EF625BB3AD919322C01A46B2 /* BitchatApp.swift */, EA706D8E5097785414646A8E /* Info.plist */, @@ -383,6 +386,7 @@ ); mainGroup = 18198ED912AAF495D8AF7763; minimizedProjectReferenceProxies = 1; + preferredProjectObjectVersion = 54; projectDirPath = ""; projectRoot = ""; targets = ( @@ -401,6 +405,7 @@ buildActionMask = 2147483647; files = ( 7DD72D928FF9DD3CA81B46B0 /* Assets.xcassets in Resources */, + 46E1E1013CC18AB66105DB27 /* LaunchScreen.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -693,7 +698,7 @@ ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES; CODE_SIGNING_ALLOWED = YES; CODE_SIGNING_REQUIRED = YES; - CODE_SIGN_ENTITLEMENTS = bitchat/bitchat.entitlements; + CODE_SIGN_ENTITLEMENTS = "bitchat/bitchat-macOS.entitlements"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; DEVELOPMENT_TEAM = L3N5LHJD5Y; @@ -776,7 +781,7 @@ ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = YES; CODE_SIGNING_ALLOWED = YES; CODE_SIGNING_REQUIRED = YES; - CODE_SIGN_ENTITLEMENTS = bitchat/bitchat.entitlements; + CODE_SIGN_ENTITLEMENTS = "bitchat/bitchat-macOS.entitlements"; CODE_SIGN_STYLE = Automatic; COMBINE_HIDPI_IMAGES = YES; DEVELOPMENT_TEAM = L3N5LHJD5Y; diff --git a/bitchat/Info.plist b/bitchat/Info.plist index 567f2c3c..17cdfb12 100644 --- a/bitchat/Info.plist +++ b/bitchat/Info.plist @@ -35,25 +35,5 @@ bitchat uses Bluetooth to create a secure mesh network for chatting with nearby users. NSBluetoothPeripheralUsageDescription bitchat uses Bluetooth to discover and connect with other bitchat users nearby. - UIBackgroundModes - - bluetooth-central - bluetooth-peripheral - - UILaunchStoryboardName - LaunchScreen - UIRequiresFullScreen - - UISupportedInterfaceOrientations - - UIInterfaceOrientationPortrait - - UISupportedInterfaceOrientations~ipad - - UIInterfaceOrientationPortrait - UIInterfaceOrientationPortraitUpsideDown - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - diff --git a/bitchat/bitchat-macOS.entitlements b/bitchat/bitchat-macOS.entitlements new file mode 100644 index 00000000..610b08cb --- /dev/null +++ b/bitchat/bitchat-macOS.entitlements @@ -0,0 +1,14 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.application-groups + + group.chat.bitchat + + com.apple.security.device.bluetooth + + + \ No newline at end of file diff --git a/project.yml b/project.yml index ea3c24a1..2c3865f2 100644 --- a/project.yml +++ b/project.yml @@ -93,7 +93,7 @@ targets: DEVELOPMENT_TEAM: L3N5LHJD5Y ASSETCATALOG_COMPILER_APPICON_NAME: AppIcon ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS: YES - CODE_SIGN_ENTITLEMENTS: bitchat/bitchat.entitlements + CODE_SIGN_ENTITLEMENTS: bitchat/bitchat-macOS.entitlements bitchatShareExtension: type: app-extension From 022050193f5bc3d7c71dd735c122abe729150ec0 Mon Sep 17 00:00:00 2001 From: jack Date: Thu, 10 Jul 2025 12:53:51 +0200 Subject: [PATCH 4/4] Fix macOS Bluetooth entitlements and remove debug logging - Created separate macOS entitlements file with required Bluetooth permission - Fixed "Bluetooth unsupported" issue on Mac by adding com.apple.security.device.bluetooth entitlement - Removed all debug logging from BluetoothMeshService - Re-enabled scan duty cycling - Reverted RSSI threshold back to -90 dBm from temporary -100 dBm debug value --- bitchat.xcodeproj/project.pbxproj | 29 ++++++----- bitchat/Info.plist | 13 +++++ bitchat/Services/BluetoothMeshService.swift | 54 +++------------------ 3 files changed, 37 insertions(+), 59 deletions(-) diff --git a/bitchat.xcodeproj/project.pbxproj b/bitchat.xcodeproj/project.pbxproj index 5a6a1e56..98936730 100644 --- a/bitchat.xcodeproj/project.pbxproj +++ b/bitchat.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 54; + objectVersion = 63; objects = { /* Begin PBXBuildFile section */ @@ -17,7 +17,6 @@ 2E71E320EA921498C57E023B /* BitchatMessageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FA8FF26ABDC1C642A8C7AE5 /* BitchatMessageTests.swift */; }; 31D147471B9F4E2815352DDA /* LinkPreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AC141774F6671FCDC347DC7 /* LinkPreviewView.swift */; }; 4274B6016F755946FBF2513E /* MessageRetentionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A85BFDDE65B4CD8BDF6DDB /* MessageRetentionService.swift */; }; - 46E1E1013CC18AB66105DB27 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 95F16C3A4A5621C74461D8D3 /* LaunchScreen.storyboard */; }; 4B747085D07A1BCE0F5BA612 /* BinaryProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2136C3E22D02D4A8DBE7EAB /* BinaryProtocol.swift */; }; 4E778E5A414571ACAC2A0F01 /* MessageRetentionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A85BFDDE65B4CD8BDF6DDB /* MessageRetentionService.swift */; }; 5D95F2BFBE257A1225998389 /* BatteryOptimizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED176FF3B274E35C2D827894 /* BatteryOptimizer.swift */; }; @@ -112,14 +111,14 @@ 3FA8FF26ABDC1C642A8C7AE5 /* BitchatMessageTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BitchatMessageTests.swift; sourceTree = ""; }; 527EB217EFDFAD4CF1C91F07 /* bitchat.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = bitchat.entitlements; sourceTree = ""; }; 53D535D9CE0B875F47402290 /* BinaryProtocolTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinaryProtocolTests.swift; sourceTree = ""; }; - 61F92EBA29C47C0FCC482F1F /* bitchatShareExtension.appex */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "wrapper.app-extension"; path = bitchatShareExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; }; + 61F92EBA29C47C0FCC482F1F /* bitchatShareExtension.appex */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "wrapper.extensionkit-extension"; path = bitchatShareExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; }; 67A85BFDDE65B4CD8BDF6DDB /* MessageRetentionService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageRetentionService.swift; sourceTree = ""; }; 6DC1563390A15C042D059CF9 /* EncryptionService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncryptionService.swift; sourceTree = ""; }; 763E0DBA9492A654FC0CDCB9 /* AppInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppInfoView.swift; sourceTree = ""; }; 8DE9CDF66D4E52D268851048 /* MessagePaddingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagePaddingTests.swift; sourceTree = ""; }; - 8F3A7C058C2C8E1A06C8CF8B /* bitchat_macOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = bitchat_macOS.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 8F3A7C058C2C8E1A06C8CF8B /* bitchat_macOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; name = bitchat_macOS.app; path = bitchat.app; sourceTree = BUILT_PRODUCTS_DIR; }; 95F16C3A4A5621C74461D8D3 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; - 96D0D41CA19EE5A772AA8434 /* bitchat_iOS.app */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.application; path = bitchat_iOS.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 96D0D41CA19EE5A772AA8434 /* bitchat.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = bitchat.app; sourceTree = BUILT_PRODUCTS_DIR; }; 9AC141774F6671FCDC347DC7 /* LinkPreviewView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkPreviewView.swift; sourceTree = ""; }; A08E03AA0C63E97C91749AEC /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; A2136C3E22D02D4A8DBE7EAB /* BinaryProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinaryProtocol.swift; sourceTree = ""; }; @@ -186,7 +185,7 @@ 9F37F9F2C353B58AC809E93B /* Products */ = { isa = PBXGroup; children = ( - 96D0D41CA19EE5A772AA8434 /* bitchat_iOS.app */, + 96D0D41CA19EE5A772AA8434 /* bitchat.app */, 8F3A7C058C2C8E1A06C8CF8B /* bitchat_macOS.app */, 61F92EBA29C47C0FCC482F1F /* bitchatShareExtension.appex */, C0DB1DE27F0AAB5092663E8E /* bitchatTests_iOS.xctest */, @@ -342,7 +341,7 @@ packageProductDependencies = ( ); productName = bitchat_iOS; - productReference = 96D0D41CA19EE5A772AA8434 /* bitchat_iOS.app */; + productReference = 96D0D41CA19EE5A772AA8434 /* bitchat.app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ @@ -386,7 +385,6 @@ ); mainGroup = 18198ED912AAF495D8AF7763; minimizedProjectReferenceProxies = 1; - preferredProjectObjectVersion = 54; projectDirPath = ""; projectRoot = ""; targets = ( @@ -405,7 +403,6 @@ buildActionMask = 2147483647; files = ( 7DD72D928FF9DD3CA81B46B0 /* Assets.xcassets in Resources */, - 46E1E1013CC18AB66105DB27 /* LaunchScreen.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -627,6 +624,8 @@ DEVELOPMENT_TEAM = L3N5LHJD5Y; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = bitchat/Info.plist; + INFOPLIST_KEY_CFBundleDisplayName = bitchat; + INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.social-networking"; IPHONEOS_DEPLOYMENT_TARGET = 16.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -635,7 +634,10 @@ PRODUCT_BUNDLE_IDENTIFIER = chat.bitchat; PRODUCT_NAME = bitchat; SDKROOT = iphoneos; - SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; + SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; @@ -677,6 +679,8 @@ DEVELOPMENT_TEAM = L3N5LHJD5Y; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = bitchat/Info.plist; + INFOPLIST_KEY_CFBundleDisplayName = bitchat; + INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.social-networking"; IPHONEOS_DEPLOYMENT_TARGET = 16.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -685,7 +689,10 @@ PRODUCT_BUNDLE_IDENTIFIER = chat.bitchat; PRODUCT_NAME = bitchat; SDKROOT = iphoneos; - SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; + SUPPORTED_PLATFORMS = "iphoneos iphonesimulator"; + SUPPORTS_MACCATALYST = NO; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO; + SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; diff --git a/bitchat/Info.plist b/bitchat/Info.plist index 17cdfb12..6e6d9504 100644 --- a/bitchat/Info.plist +++ b/bitchat/Info.plist @@ -35,5 +35,18 @@ bitchat uses Bluetooth to create a secure mesh network for chatting with nearby users. NSBluetoothPeripheralUsageDescription bitchat uses Bluetooth to discover and connect with other bitchat users nearby. + UILaunchStoryboardName + LaunchScreen + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + diff --git a/bitchat/Services/BluetoothMeshService.swift b/bitchat/Services/BluetoothMeshService.swift index 979678e2..13a5cf70 100644 --- a/bitchat/Services/BluetoothMeshService.swift +++ b/bitchat/Services/BluetoothMeshService.swift @@ -260,13 +260,11 @@ class BluetoothMeshService: NSObject { var randomBytes = [UInt8](repeating: 0, count: 4) _ = SecRandomCopyBytes(kSecRandomDefault, 4, &randomBytes) self.myPeerID = randomBytes.map { String(format: "%02x", $0) }.joined() - print("[BLUETOOTH DEBUG] BluetoothMeshService initializing with peer ID: \(self.myPeerID)") super.init() centralManager = CBCentralManager(delegate: self, queue: nil) peripheralManager = CBPeripheralManager(delegate: self, queue: nil) - print("[BLUETOOTH DEBUG] Central and Peripheral managers created") // Start bloom filter reset timer (reset every 5 minutes) bloomFilterResetTimer = Timer.scheduledTimer(withTimeInterval: 300.0, repeats: true) { [weak self] _ in @@ -281,7 +279,6 @@ class BluetoothMeshService: NSObject { self.processedMessages.removeAll() self.processedKeyExchanges.removeAll() - print("[BloomFilter] Reset with network size: \(networkSize), memory: \(self.messageBloomFilter.memorySizeBytes) bytes") } } @@ -364,22 +361,13 @@ class BluetoothMeshService: NSObject { func startServices() { // Starting services - print("[BLUETOOTH DEBUG] startServices called") - print("[BLUETOOTH DEBUG] Central state: \(centralManager?.state.rawValue ?? -1), Peripheral state: \(peripheralManager?.state.rawValue ?? -1)") - // Start both central and peripheral services if centralManager?.state == .poweredOn { - print("[BLUETOOTH DEBUG] Central already powered on, starting scan") startScanning() - } else { - print("[BLUETOOTH DEBUG] Central not yet powered on") } if peripheralManager?.state == .poweredOn { - print("[BLUETOOTH DEBUG] Peripheral already powered on, setting up") setupPeripheral() startAdvertising() - } else { - print("[BLUETOOTH DEBUG] Peripheral not yet powered on") } // Send initial announces after services are ready @@ -422,9 +410,7 @@ class BluetoothMeshService: NSObject { } func startAdvertising() { - print("[BLUETOOTH DEBUG] startAdvertising called, peripheral state: \(peripheralManager?.state.rawValue ?? -1)") guard peripheralManager?.state == .poweredOn else { - print("[BLUETOOTH DEBUG] Cannot start advertising, peripheral not powered on") return } @@ -438,15 +424,12 @@ class BluetoothMeshService: NSObject { CBAdvertisementDataLocalNameKey: myPeerID ] - print("[BLUETOOTH DEBUG] Starting advertising with service UUID: \(BluetoothMeshService.serviceUUID), peerID: \(myPeerID)") isAdvertising = true peripheralManager?.startAdvertising(advertisementData) } func startScanning() { - print("[BLUETOOTH DEBUG] startScanning called, central state: \(centralManager?.state.rawValue ?? -1)") guard centralManager?.state == .poweredOn else { - print("[BLUETOOTH DEBUG] Cannot start scanning, central not powered on") return } @@ -455,19 +438,17 @@ class BluetoothMeshService: NSObject { CBCentralManagerScanOptionAllowDuplicatesKey: true ] - print("[BLUETOOTH DEBUG] Starting scan for peripherals with service UUID: \(BluetoothMeshService.serviceUUID)") centralManager?.scanForPeripherals( withServices: [BluetoothMeshService.serviceUUID], options: scanOptions ) - print("[BLUETOOTH DEBUG] Scan started successfully") // Update scan parameters based on battery before starting updateScanParametersForBattery() // Implement scan duty cycling for battery efficiency // TEMPORARILY DISABLED FOR DEBUGGING - // scheduleScanDutyCycle() + scheduleScanDutyCycle() } private func scheduleScanDutyCycle() { @@ -481,7 +462,6 @@ class BluetoothMeshService: NSObject { if self.isActivelyScanning { // Pause scanning to save battery - print("[BLUETOOTH DEBUG] Pausing scan after \(self.activeScanDuration) seconds") self.centralManager?.stopScan() self.isActivelyScanning = false @@ -489,7 +469,6 @@ class BluetoothMeshService: NSObject { DispatchQueue.main.asyncAfter(deadline: .now() + self.scanPauseDuration) { [weak self] in guard let self = self else { return } if self.centralManager?.state == .poweredOn { - print("[BLUETOOTH DEBUG] Resuming scan after \(self.scanPauseDuration) seconds pause") self.centralManager?.scanForPeripherals( withServices: [BluetoothMeshService.serviceUUID], options: [CBCentralManagerScanOptionAllowDuplicatesKey: true] @@ -502,7 +481,6 @@ class BluetoothMeshService: NSObject { } private func setupPeripheral() { - print("[BLUETOOTH DEBUG] Setting up peripheral with service UUID: \(BluetoothMeshService.serviceUUID)") let characteristic = CBMutableCharacteristic( type: BluetoothMeshService.characteristicUUID, properties: [.read, .write, .writeWithoutResponse, .notify], @@ -513,7 +491,6 @@ class BluetoothMeshService: NSObject { let service = CBMutableService(type: BluetoothMeshService.serviceUUID, primary: true) service.characteristics = [characteristic] - print("[BLUETOOTH DEBUG] Adding service to peripheral manager") peripheralManager?.add(service) self.characteristic = characteristic } @@ -1439,7 +1416,6 @@ class BluetoothMeshService: NSObject { return } else { // False positive from Bloom filter - print("[BloomFilter] False positive detected for message: \(messageID)") } } @@ -1449,7 +1425,6 @@ class BluetoothMeshService: NSObject { // Log statistics periodically if messageBloomFilter.insertCount % 100 == 0 { let fpRate = messageBloomFilter.estimatedFalsePositiveRate - print("[BloomFilter] Items: \(messageBloomFilter.insertCount), Est. FP rate: \(String(format: "%.3f%%", fpRate * 100))") } // Reset bloom filter periodically to prevent saturation @@ -2277,16 +2252,10 @@ extension BluetoothMeshService: CBCentralManagerDelegate { @unknown default: stateString = "unknown state(\(central.state.rawValue))" } - print("[BLUETOOTH DEBUG] Central manager state changed to: \(stateString)") - if central.state == .unsupported { - print("[BLUETOOTH DEBUG] Bluetooth is not supported on this device") } else if central.state == .unauthorized { - print("[BLUETOOTH DEBUG] Bluetooth is unauthorized. Check app permissions in Settings") } else if central.state == .poweredOff { - print("[BLUETOOTH DEBUG] Bluetooth is powered off. Please turn on Bluetooth") } else if central.state == .poweredOn { - print("[BLUETOOTH DEBUG] Central powered on, starting scan") startScanning() // Send announces when central manager is ready @@ -2641,17 +2610,14 @@ extension BluetoothMeshService: CBPeripheralManagerDelegate { @unknown default: stateString = "unknown state(\(peripheral.state.rawValue))" } - print("[BLUETOOTH DEBUG] Peripheral manager state changed to: \(stateString)") - switch peripheral.state { case .unsupported: - print("[BLUETOOTH DEBUG] Bluetooth is not supported on this device") + break case .unauthorized: - print("[BLUETOOTH DEBUG] Bluetooth is unauthorized. Check app permissions in Settings") + break case .poweredOff: - print("[BLUETOOTH DEBUG] Bluetooth is powered off. Please turn on Bluetooth") + break case .poweredOn: - print("[BLUETOOTH DEBUG] Peripheral powered on, setting up and advertising") setupPeripheral() startAdvertising() @@ -2665,19 +2631,11 @@ extension BluetoothMeshService: CBPeripheralManagerDelegate { } func peripheralManager(_ peripheral: CBPeripheralManager, didAdd service: CBService, error: Error?) { - if let error = error { - print("[BLUETOOTH DEBUG] Failed to add service: \(error.localizedDescription)") - } else { - print("[BLUETOOTH DEBUG] Service added successfully: \(service.uuid)") - } + // Service added } func peripheralManagerDidStartAdvertising(_ peripheral: CBPeripheralManager, error: Error?) { - if let error = error { - print("[BLUETOOTH DEBUG] Failed to start advertising: \(error.localizedDescription)") - } else { - print("[BLUETOOTH DEBUG] Advertising started successfully") - } + // Advertising state changed } func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveWrite requests: [CBATTRequest]) {