HomeiOS Developmentios - CBCentralManager peripheral discovery deteriorating after an extended search

ios – CBCentralManager peripheral discovery deteriorating after an extended search


I’m presently creating an app that’s gonna be used for connecting with BLE gadgets. All the things works high-quality for essentially the most half, however I’ve observed a bizarre behaviour from the CBCentralManager class. The longer it runs a seek for BLE peripherals, the much less typically it may really discover the identical peripheral (I’m speaking about discovering commercial packages). I’ve tried some third occasion apps (BLE scanners and many others.), and so they can discover my peripheral with none issues. It does promote each X seconds, and the apps can often discover it after 1-3 * X. Here’s a quite simple implementation of the BLE discovery code that exhibits the invention deterioration signs:

import CoreBluetooth

class BluetoothTestClass: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate {
    
    non-public let supervisor: CBCentralManager
    
    override init() {
        self.supervisor = CBCentralManager(delegate: nil, queue: .most important, choices: [CBCentralManagerScanOptionAllowDuplicatesKey:true])
        tremendous.init()
        
        self.supervisor.delegate = self
    }
    
    func startSearch() {
        DispatchQueue.most important.asyncAfter(deadline: .now() + 1) {
            self.supervisor.scanForPeripherals(withServices: nil, choices: [CBCentralManagerOptionShowPowerAlertKey:true,
                                                                    CBCentralManagerScanOptionAllowDuplicatesKey:true])
        }
    }
    
    func centralManagerDidUpdateState(_ central: CBCentralManager) {
    }
    
    var peripherals: [CBPeripheral] = []
    func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
        peripherals.append(peripheral)
        print(Date())
    }
}

The one factor that I discovered that helps at this level, is resetting the search each 30 seconds, then the search outcomes are fairly near what I can see within the third occasion scanner apps (peripheral discovered after 1-3 * X seconds).

Any leads, concepts and even breadcrumbs on this matter will probably be extremely appreciated.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments