Skip to content

Commit

Permalink
Fix duplicate corebluetooth peripherals having their own Peripheral i…
Browse files Browse the repository at this point in the history
…nstance leading delegate issues on iOS 16.4
  • Loading branch information
jordanebelanger committed Apr 20, 2023
1 parent 7f279a2 commit 83694e2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions Sources/CentralProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ extension CentralProxy {
// MARK: Scan requests
private final class PeripheralScanRequest {
let callback: PeripheralScanCallback
var peripherals: [Peripheral] = []
var peripherals: [UUID: Peripheral] = [:]

init(callback: @escaping PeripheralScanCallback) {
self.callback = callback
Expand Down Expand Up @@ -147,7 +147,7 @@ extension CentralProxy {

if let scanRequest = self.scanRequest {
self.scanRequest = nil
scanRequest.callback(.scanStopped(peripherals: scanRequest.peripherals, error: error))
scanRequest.callback(.scanStopped(peripherals: scanRequest.peripherals.values.map({$0}), error: error))
}
}

Expand Down Expand Up @@ -398,8 +398,10 @@ extension CentralProxy: CBCentralManagerDelegate {
return
}

guard scanRequest.peripherals[peripheral.identifier] == nil else { return }

let peripheral = Peripheral(peripheral: peripheral)
scanRequest.peripherals.append(peripheral)
scanRequest.peripherals[peripheral.identifier] = peripheral

var rssiOptional: Int? = Int(truncating: RSSI)
if let rssi = rssiOptional, rssi == 127 {
Expand Down
2 changes: 1 addition & 1 deletion SwiftyBluetooth.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'SwiftyBluetooth'
s.version = '3.0.1'
s.version = '3.1.0'
s.license = 'MIT'
s.homepage = 'https://github.com/jordanebelanger/SwiftyBluetooth'
s.authors = { 'Jordane Belanger' => '[email protected]' }
Expand Down

0 comments on commit 83694e2

Please sign in to comment.