Skip to content

Commit

Permalink
Merge pull request #79 from NordicSemiconductor/bugfix/multiple-manag…
Browse files Browse the repository at this point in the history
…ers-retrieval

Bug fix: Retrieving peripherals multiple times
  • Loading branch information
philips77 authored Feb 14, 2023
2 parents 829358b + 98c90dd commit e1743a8
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions CoreBluetoothMock/Classes/CBMCentralManagerMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,6 @@ open class CBMCentralManagerMock: CBMCentralManager {
open override func retrievePeripherals(withIdentifiers identifiers: [UUID]) -> [CBMPeripheral] {
// Starting from iOS 13, this method returns peripherals only in ON state.
guard ensurePoweredOn() else { return [] }
// Get the peripherals already known to this central manager.
let localPeripherals = peripherals[identifiers]
// Also, look for them among other managers, and copy them to the local
// manager.
let missingIdentifiers = identifiers.filter { peripherals[$0] == nil }
Expand Down Expand Up @@ -667,8 +665,10 @@ open class CBMCentralManagerMock: CBMCentralManager {
peripheralsCached.forEach {
peripherals[$0.identifier] = $0
}
// Now, with updated peripherals, get those known to this central manager.
let localPeripherals = peripherals[identifiers]
// Return them in the same order as requested, some may be missing.
return (localPeripherals + peripheralsKnownByOtherManagers + peripheralsCached)
return localPeripherals
.sorted {
let firstIndex = identifiers.firstIndex(of: $0.identifier)!
let secondIndex = identifiers.firstIndex(of: $1.identifier)!
Expand Down

0 comments on commit e1743a8

Please sign in to comment.