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
This commit is contained in:
jack
2025-07-10 12:53:51 +02:00
parent c6d74b7574
commit 022050193f
3 changed files with 37 additions and 59 deletions
+18 -11
View File
@@ -3,7 +3,7 @@
archiveVersion = 1; archiveVersion = 1;
classes = { classes = {
}; };
objectVersion = 54; objectVersion = 63;
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
@@ -17,7 +17,6 @@
2E71E320EA921498C57E023B /* BitchatMessageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FA8FF26ABDC1C642A8C7AE5 /* BitchatMessageTests.swift */; }; 2E71E320EA921498C57E023B /* BitchatMessageTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FA8FF26ABDC1C642A8C7AE5 /* BitchatMessageTests.swift */; };
31D147471B9F4E2815352DDA /* LinkPreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AC141774F6671FCDC347DC7 /* LinkPreviewView.swift */; }; 31D147471B9F4E2815352DDA /* LinkPreviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AC141774F6671FCDC347DC7 /* LinkPreviewView.swift */; };
4274B6016F755946FBF2513E /* MessageRetentionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A85BFDDE65B4CD8BDF6DDB /* MessageRetentionService.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 */; }; 4B747085D07A1BCE0F5BA612 /* BinaryProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = A2136C3E22D02D4A8DBE7EAB /* BinaryProtocol.swift */; };
4E778E5A414571ACAC2A0F01 /* MessageRetentionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A85BFDDE65B4CD8BDF6DDB /* MessageRetentionService.swift */; }; 4E778E5A414571ACAC2A0F01 /* MessageRetentionService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 67A85BFDDE65B4CD8BDF6DDB /* MessageRetentionService.swift */; };
5D95F2BFBE257A1225998389 /* BatteryOptimizer.swift in Sources */ = {isa = PBXBuildFile; fileRef = ED176FF3B274E35C2D827894 /* BatteryOptimizer.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 = "<group>"; }; 3FA8FF26ABDC1C642A8C7AE5 /* BitchatMessageTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BitchatMessageTests.swift; sourceTree = "<group>"; };
527EB217EFDFAD4CF1C91F07 /* bitchat.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = bitchat.entitlements; sourceTree = "<group>"; }; 527EB217EFDFAD4CF1C91F07 /* bitchat.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = bitchat.entitlements; sourceTree = "<group>"; };
53D535D9CE0B875F47402290 /* BinaryProtocolTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinaryProtocolTests.swift; sourceTree = "<group>"; }; 53D535D9CE0B875F47402290 /* BinaryProtocolTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinaryProtocolTests.swift; sourceTree = "<group>"; };
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 = "<group>"; }; 67A85BFDDE65B4CD8BDF6DDB /* MessageRetentionService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageRetentionService.swift; sourceTree = "<group>"; };
6DC1563390A15C042D059CF9 /* EncryptionService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncryptionService.swift; sourceTree = "<group>"; }; 6DC1563390A15C042D059CF9 /* EncryptionService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncryptionService.swift; sourceTree = "<group>"; };
763E0DBA9492A654FC0CDCB9 /* AppInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppInfoView.swift; sourceTree = "<group>"; }; 763E0DBA9492A654FC0CDCB9 /* AppInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppInfoView.swift; sourceTree = "<group>"; };
8DE9CDF66D4E52D268851048 /* MessagePaddingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagePaddingTests.swift; sourceTree = "<group>"; }; 8DE9CDF66D4E52D268851048 /* MessagePaddingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagePaddingTests.swift; sourceTree = "<group>"; };
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 = "<group>"; }; 95F16C3A4A5621C74461D8D3 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = "<group>"; };
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 = "<group>"; }; 9AC141774F6671FCDC347DC7 /* LinkPreviewView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LinkPreviewView.swift; sourceTree = "<group>"; };
A08E03AA0C63E97C91749AEC /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; }; A08E03AA0C63E97C91749AEC /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
A2136C3E22D02D4A8DBE7EAB /* BinaryProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinaryProtocol.swift; sourceTree = "<group>"; }; A2136C3E22D02D4A8DBE7EAB /* BinaryProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BinaryProtocol.swift; sourceTree = "<group>"; };
@@ -186,7 +185,7 @@
9F37F9F2C353B58AC809E93B /* Products */ = { 9F37F9F2C353B58AC809E93B /* Products */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
96D0D41CA19EE5A772AA8434 /* bitchat_iOS.app */, 96D0D41CA19EE5A772AA8434 /* bitchat.app */,
8F3A7C058C2C8E1A06C8CF8B /* bitchat_macOS.app */, 8F3A7C058C2C8E1A06C8CF8B /* bitchat_macOS.app */,
61F92EBA29C47C0FCC482F1F /* bitchatShareExtension.appex */, 61F92EBA29C47C0FCC482F1F /* bitchatShareExtension.appex */,
C0DB1DE27F0AAB5092663E8E /* bitchatTests_iOS.xctest */, C0DB1DE27F0AAB5092663E8E /* bitchatTests_iOS.xctest */,
@@ -342,7 +341,7 @@
packageProductDependencies = ( packageProductDependencies = (
); );
productName = bitchat_iOS; productName = bitchat_iOS;
productReference = 96D0D41CA19EE5A772AA8434 /* bitchat_iOS.app */; productReference = 96D0D41CA19EE5A772AA8434 /* bitchat.app */;
productType = "com.apple.product-type.application"; productType = "com.apple.product-type.application";
}; };
/* End PBXNativeTarget section */ /* End PBXNativeTarget section */
@@ -386,7 +385,6 @@
); );
mainGroup = 18198ED912AAF495D8AF7763; mainGroup = 18198ED912AAF495D8AF7763;
minimizedProjectReferenceProxies = 1; minimizedProjectReferenceProxies = 1;
preferredProjectObjectVersion = 54;
projectDirPath = ""; projectDirPath = "";
projectRoot = ""; projectRoot = "";
targets = ( targets = (
@@ -405,7 +403,6 @@
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
7DD72D928FF9DD3CA81B46B0 /* Assets.xcassets in Resources */, 7DD72D928FF9DD3CA81B46B0 /* Assets.xcassets in Resources */,
46E1E1013CC18AB66105DB27 /* LaunchScreen.storyboard in Resources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };
@@ -627,6 +624,8 @@
DEVELOPMENT_TEAM = L3N5LHJD5Y; DEVELOPMENT_TEAM = L3N5LHJD5Y;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = bitchat/Info.plist; INFOPLIST_FILE = bitchat/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = bitchat;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.social-networking";
IPHONEOS_DEPLOYMENT_TARGET = 16.0; IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
@@ -635,7 +634,10 @@
PRODUCT_BUNDLE_IDENTIFIER = chat.bitchat; PRODUCT_BUNDLE_IDENTIFIER = chat.bitchat;
PRODUCT_NAME = bitchat; PRODUCT_NAME = bitchat;
SDKROOT = iphoneos; 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; SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
}; };
@@ -677,6 +679,8 @@
DEVELOPMENT_TEAM = L3N5LHJD5Y; DEVELOPMENT_TEAM = L3N5LHJD5Y;
ENABLE_PREVIEWS = YES; ENABLE_PREVIEWS = YES;
INFOPLIST_FILE = bitchat/Info.plist; INFOPLIST_FILE = bitchat/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = bitchat;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.social-networking";
IPHONEOS_DEPLOYMENT_TARGET = 16.0; IPHONEOS_DEPLOYMENT_TARGET = 16.0;
LD_RUNPATH_SEARCH_PATHS = ( LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)", "$(inherited)",
@@ -685,7 +689,10 @@
PRODUCT_BUNDLE_IDENTIFIER = chat.bitchat; PRODUCT_BUNDLE_IDENTIFIER = chat.bitchat;
PRODUCT_NAME = bitchat; PRODUCT_NAME = bitchat;
SDKROOT = iphoneos; 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; SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2"; TARGETED_DEVICE_FAMILY = "1,2";
}; };
+13
View File
@@ -35,5 +35,18 @@
<string>bitchat uses Bluetooth to create a secure mesh network for chatting with nearby users.</string> <string>bitchat uses Bluetooth to create a secure mesh network for chatting with nearby users.</string>
<key>NSBluetoothPeripheralUsageDescription</key> <key>NSBluetoothPeripheralUsageDescription</key>
<string>bitchat uses Bluetooth to discover and connect with other bitchat users nearby.</string> <string>bitchat uses Bluetooth to discover and connect with other bitchat users nearby.</string>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
</dict> </dict>
</plist> </plist>
+6 -48
View File
@@ -260,13 +260,11 @@ class BluetoothMeshService: NSObject {
var randomBytes = [UInt8](repeating: 0, count: 4) var randomBytes = [UInt8](repeating: 0, count: 4)
_ = SecRandomCopyBytes(kSecRandomDefault, 4, &randomBytes) _ = SecRandomCopyBytes(kSecRandomDefault, 4, &randomBytes)
self.myPeerID = randomBytes.map { String(format: "%02x", $0) }.joined() self.myPeerID = randomBytes.map { String(format: "%02x", $0) }.joined()
print("[BLUETOOTH DEBUG] BluetoothMeshService initializing with peer ID: \(self.myPeerID)")
super.init() super.init()
centralManager = CBCentralManager(delegate: self, queue: nil) centralManager = CBCentralManager(delegate: self, queue: nil)
peripheralManager = CBPeripheralManager(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) // Start bloom filter reset timer (reset every 5 minutes)
bloomFilterResetTimer = Timer.scheduledTimer(withTimeInterval: 300.0, repeats: true) { [weak self] _ in bloomFilterResetTimer = Timer.scheduledTimer(withTimeInterval: 300.0, repeats: true) { [weak self] _ in
@@ -281,7 +279,6 @@ class BluetoothMeshService: NSObject {
self.processedMessages.removeAll() self.processedMessages.removeAll()
self.processedKeyExchanges.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() { func startServices() {
// Starting services // 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 // Start both central and peripheral services
if centralManager?.state == .poweredOn { if centralManager?.state == .poweredOn {
print("[BLUETOOTH DEBUG] Central already powered on, starting scan")
startScanning() startScanning()
} else {
print("[BLUETOOTH DEBUG] Central not yet powered on")
} }
if peripheralManager?.state == .poweredOn { if peripheralManager?.state == .poweredOn {
print("[BLUETOOTH DEBUG] Peripheral already powered on, setting up")
setupPeripheral() setupPeripheral()
startAdvertising() startAdvertising()
} else {
print("[BLUETOOTH DEBUG] Peripheral not yet powered on")
} }
// Send initial announces after services are ready // Send initial announces after services are ready
@@ -422,9 +410,7 @@ class BluetoothMeshService: NSObject {
} }
func startAdvertising() { func startAdvertising() {
print("[BLUETOOTH DEBUG] startAdvertising called, peripheral state: \(peripheralManager?.state.rawValue ?? -1)")
guard peripheralManager?.state == .poweredOn else { guard peripheralManager?.state == .poweredOn else {
print("[BLUETOOTH DEBUG] Cannot start advertising, peripheral not powered on")
return return
} }
@@ -438,15 +424,12 @@ class BluetoothMeshService: NSObject {
CBAdvertisementDataLocalNameKey: myPeerID CBAdvertisementDataLocalNameKey: myPeerID
] ]
print("[BLUETOOTH DEBUG] Starting advertising with service UUID: \(BluetoothMeshService.serviceUUID), peerID: \(myPeerID)")
isAdvertising = true isAdvertising = true
peripheralManager?.startAdvertising(advertisementData) peripheralManager?.startAdvertising(advertisementData)
} }
func startScanning() { func startScanning() {
print("[BLUETOOTH DEBUG] startScanning called, central state: \(centralManager?.state.rawValue ?? -1)")
guard centralManager?.state == .poweredOn else { guard centralManager?.state == .poweredOn else {
print("[BLUETOOTH DEBUG] Cannot start scanning, central not powered on")
return return
} }
@@ -455,19 +438,17 @@ class BluetoothMeshService: NSObject {
CBCentralManagerScanOptionAllowDuplicatesKey: true CBCentralManagerScanOptionAllowDuplicatesKey: true
] ]
print("[BLUETOOTH DEBUG] Starting scan for peripherals with service UUID: \(BluetoothMeshService.serviceUUID)")
centralManager?.scanForPeripherals( centralManager?.scanForPeripherals(
withServices: [BluetoothMeshService.serviceUUID], withServices: [BluetoothMeshService.serviceUUID],
options: scanOptions options: scanOptions
) )
print("[BLUETOOTH DEBUG] Scan started successfully")
// Update scan parameters based on battery before starting // Update scan parameters based on battery before starting
updateScanParametersForBattery() updateScanParametersForBattery()
// Implement scan duty cycling for battery efficiency // Implement scan duty cycling for battery efficiency
// TEMPORARILY DISABLED FOR DEBUGGING // TEMPORARILY DISABLED FOR DEBUGGING
// scheduleScanDutyCycle() scheduleScanDutyCycle()
} }
private func scheduleScanDutyCycle() { private func scheduleScanDutyCycle() {
@@ -481,7 +462,6 @@ class BluetoothMeshService: NSObject {
if self.isActivelyScanning { if self.isActivelyScanning {
// Pause scanning to save battery // Pause scanning to save battery
print("[BLUETOOTH DEBUG] Pausing scan after \(self.activeScanDuration) seconds")
self.centralManager?.stopScan() self.centralManager?.stopScan()
self.isActivelyScanning = false self.isActivelyScanning = false
@@ -489,7 +469,6 @@ class BluetoothMeshService: NSObject {
DispatchQueue.main.asyncAfter(deadline: .now() + self.scanPauseDuration) { [weak self] in DispatchQueue.main.asyncAfter(deadline: .now() + self.scanPauseDuration) { [weak self] in
guard let self = self else { return } guard let self = self else { return }
if self.centralManager?.state == .poweredOn { if self.centralManager?.state == .poweredOn {
print("[BLUETOOTH DEBUG] Resuming scan after \(self.scanPauseDuration) seconds pause")
self.centralManager?.scanForPeripherals( self.centralManager?.scanForPeripherals(
withServices: [BluetoothMeshService.serviceUUID], withServices: [BluetoothMeshService.serviceUUID],
options: [CBCentralManagerScanOptionAllowDuplicatesKey: true] options: [CBCentralManagerScanOptionAllowDuplicatesKey: true]
@@ -502,7 +481,6 @@ class BluetoothMeshService: NSObject {
} }
private func setupPeripheral() { private func setupPeripheral() {
print("[BLUETOOTH DEBUG] Setting up peripheral with service UUID: \(BluetoothMeshService.serviceUUID)")
let characteristic = CBMutableCharacteristic( let characteristic = CBMutableCharacteristic(
type: BluetoothMeshService.characteristicUUID, type: BluetoothMeshService.characteristicUUID,
properties: [.read, .write, .writeWithoutResponse, .notify], properties: [.read, .write, .writeWithoutResponse, .notify],
@@ -513,7 +491,6 @@ class BluetoothMeshService: NSObject {
let service = CBMutableService(type: BluetoothMeshService.serviceUUID, primary: true) let service = CBMutableService(type: BluetoothMeshService.serviceUUID, primary: true)
service.characteristics = [characteristic] service.characteristics = [characteristic]
print("[BLUETOOTH DEBUG] Adding service to peripheral manager")
peripheralManager?.add(service) peripheralManager?.add(service)
self.characteristic = characteristic self.characteristic = characteristic
} }
@@ -1439,7 +1416,6 @@ class BluetoothMeshService: NSObject {
return return
} else { } else {
// False positive from Bloom filter // False positive from Bloom filter
print("[BloomFilter] False positive detected for message: \(messageID)")
} }
} }
@@ -1449,7 +1425,6 @@ class BluetoothMeshService: NSObject {
// Log statistics periodically // Log statistics periodically
if messageBloomFilter.insertCount % 100 == 0 { if messageBloomFilter.insertCount % 100 == 0 {
let fpRate = messageBloomFilter.estimatedFalsePositiveRate let fpRate = messageBloomFilter.estimatedFalsePositiveRate
print("[BloomFilter] Items: \(messageBloomFilter.insertCount), Est. FP rate: \(String(format: "%.3f%%", fpRate * 100))")
} }
// Reset bloom filter periodically to prevent saturation // Reset bloom filter periodically to prevent saturation
@@ -2277,16 +2252,10 @@ extension BluetoothMeshService: CBCentralManagerDelegate {
@unknown default: stateString = "unknown state(\(central.state.rawValue))" @unknown default: stateString = "unknown state(\(central.state.rawValue))"
} }
print("[BLUETOOTH DEBUG] Central manager state changed to: \(stateString)")
if central.state == .unsupported { if central.state == .unsupported {
print("[BLUETOOTH DEBUG] Bluetooth is not supported on this device")
} else if central.state == .unauthorized { } else if central.state == .unauthorized {
print("[BLUETOOTH DEBUG] Bluetooth is unauthorized. Check app permissions in Settings")
} else if central.state == .poweredOff { } else if central.state == .poweredOff {
print("[BLUETOOTH DEBUG] Bluetooth is powered off. Please turn on Bluetooth")
} else if central.state == .poweredOn { } else if central.state == .poweredOn {
print("[BLUETOOTH DEBUG] Central powered on, starting scan")
startScanning() startScanning()
// Send announces when central manager is ready // Send announces when central manager is ready
@@ -2641,17 +2610,14 @@ extension BluetoothMeshService: CBPeripheralManagerDelegate {
@unknown default: stateString = "unknown state(\(peripheral.state.rawValue))" @unknown default: stateString = "unknown state(\(peripheral.state.rawValue))"
} }
print("[BLUETOOTH DEBUG] Peripheral manager state changed to: \(stateString)")
switch peripheral.state { switch peripheral.state {
case .unsupported: case .unsupported:
print("[BLUETOOTH DEBUG] Bluetooth is not supported on this device") break
case .unauthorized: case .unauthorized:
print("[BLUETOOTH DEBUG] Bluetooth is unauthorized. Check app permissions in Settings") break
case .poweredOff: case .poweredOff:
print("[BLUETOOTH DEBUG] Bluetooth is powered off. Please turn on Bluetooth") break
case .poweredOn: case .poweredOn:
print("[BLUETOOTH DEBUG] Peripheral powered on, setting up and advertising")
setupPeripheral() setupPeripheral()
startAdvertising() startAdvertising()
@@ -2665,19 +2631,11 @@ extension BluetoothMeshService: CBPeripheralManagerDelegate {
} }
func peripheralManager(_ peripheral: CBPeripheralManager, didAdd service: CBService, error: Error?) { func peripheralManager(_ peripheral: CBPeripheralManager, didAdd service: CBService, error: Error?) {
if let error = error { // Service added
print("[BLUETOOTH DEBUG] Failed to add service: \(error.localizedDescription)")
} else {
print("[BLUETOOTH DEBUG] Service added successfully: \(service.uuid)")
}
} }
func peripheralManagerDidStartAdvertising(_ peripheral: CBPeripheralManager, error: Error?) { func peripheralManagerDidStartAdvertising(_ peripheral: CBPeripheralManager, error: Error?) {
if let error = error { // Advertising state changed
print("[BLUETOOTH DEBUG] Failed to start advertising: \(error.localizedDescription)")
} else {
print("[BLUETOOTH DEBUG] Advertising started successfully")
}
} }
func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveWrite requests: [CBATTRequest]) { func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveWrite requests: [CBATTRequest]) {