Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions RileyLinkBLEKit/RileyLinkBluetoothDeviceProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,21 @@ public class RileyLinkBluetoothDeviceProvider: NSObject {
super.init()

centralQueue.sync {
#if os(iOS) // watchOS has no CoreBluetooth state restoration
central = CBCentralManager(
delegate: self,
queue: centralQueue,
options: [
CBCentralManagerOptionRestoreIdentifierKey: "com.rileylink.CentralManager"
]
)
#else
central = CBCentralManager(
delegate: self,
queue: centralQueue,
options: nil
)
#endif
}
}

Expand Down Expand Up @@ -259,6 +267,7 @@ extension Array where Element == RileyLinkBluetoothDevice {

// MARK: - Delegate methods called on `centralQueue`
extension RileyLinkBluetoothDeviceProvider: CBCentralManagerDelegate {
#if os(iOS) // watchOS has no CoreBluetooth state restoration (willRestoreState / restored-state keys are iOS-only)
public func centralManager(_ central: CBCentralManager, willRestoreState dict: [String : Any]) {
log.default("%@", #function)

Expand All @@ -270,6 +279,7 @@ extension RileyLinkBluetoothDeviceProvider: CBCentralManagerDelegate {
addPeripheral(peripheral)
}
}
#endif

public func centralManagerDidUpdateState(_ central: CBCentralManager) {
log.default("%@: %@", #function, central.state.description)
Expand Down
Loading