Skip to content

Commit 3a043a0

Browse files
authored
CA-2351: Add Background BLE support for iOS (Part 2) (#552)
1 parent ffd0008 commit 3a043a0

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

core/src/appleMain/kotlin/CentralManager.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,11 @@ public class CentralManager internal constructor() {
4040

4141
private val dispatcher = QueueDispatcher(DISPATCH_QUEUE_LABEL)
4242
internal val delegate = CentralManagerDelegate()
43-
private val cbOptions = mutableMapOf<Any?, Any>(CBCentralManagerOptionRestoreIdentifierKey to CBCENTRALMANAGER_RESTORATION_ID + consumerId).toMap()
44-
private val cbCentralManager = CBCentralManager(delegate, dispatcher.dispatchQueue, cbOptions)
43+
private val cbCentralManager = CBCentralManager(
44+
delegate,
45+
dispatcher.dispatchQueue,
46+
options = mapOf(CBCentralManagerOptionRestoreIdentifierKey to "$CBCENTRALMANAGER_RESTORATION_ID-$consumerId"),
47+
)
4548

4649
internal suspend fun scanForPeripheralsWithServices(
4750
services: List<Uuid>?,

core/src/appleMain/kotlin/CentralManagerDelegate.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ internal class CentralManagerDelegate : NSObject(), CBCentralManagerDelegateProt
121121
}
122122

123123
override fun centralManager(central: CBCentralManager, willRestoreState: Map<Any?, *>) {
124-
// NO OP
124+
// No-op: From the documentation: Tells the delegate the system is about to restore the central manager, as part of relaunching the app into the background.
125+
// Use this method to synchronize the state of your app with the state of the Bluetooth system.
126+
// Since the rest of Kable is handling the "synchronize," there's nothing to do here.
125127
}
126128

127129
/* Monitoring the Central Manager’s Authorization */

core/src/appleMain/kotlin/ScannerBuilder.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import com.juul.kable.logs.Logging
55
import com.juul.kable.logs.LoggingBuilder
66
import platform.CoreBluetooth.CBCentralManagerScanOptionAllowDuplicatesKey
77
import platform.CoreBluetooth.CBCentralManagerScanOptionSolicitedServiceUUIDsKey
8-
import platform.Foundation.NSArray
98

109
public actual class ScannerBuilder {
1110

@@ -36,7 +35,7 @@ public actual class ScannerBuilder {
3635
options[CBCentralManagerScanOptionAllowDuplicatesKey] = it
3736
}
3837
solicitedServiceUuids?.also { uuids ->
39-
options[CBCentralManagerScanOptionSolicitedServiceUUIDsKey] = uuids.map { it.toCBUUID() } as NSArray
38+
options[CBCentralManagerScanOptionSolicitedServiceUUIDsKey] = uuids.map(Uuid::toCBUUID)
4039
}
4140

4241
return CentralManagerCoreBluetoothScanner(

0 commit comments

Comments
 (0)