Skip to content

Commit

Permalink
CA-2351: Add Background BLE support for iOS (Part 2) (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
Phoenix7351 authored Aug 21, 2023
1 parent ffd0008 commit 3a043a0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
7 changes: 5 additions & 2 deletions core/src/appleMain/kotlin/CentralManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ public class CentralManager internal constructor() {

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

internal suspend fun scanForPeripheralsWithServices(
services: List<Uuid>?,
Expand Down
4 changes: 3 additions & 1 deletion core/src/appleMain/kotlin/CentralManagerDelegate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ internal class CentralManagerDelegate : NSObject(), CBCentralManagerDelegateProt
}

override fun centralManager(central: CBCentralManager, willRestoreState: Map<Any?, *>) {
// NO OP
// 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.
// Use this method to synchronize the state of your app with the state of the Bluetooth system.
// Since the rest of Kable is handling the "synchronize," there's nothing to do here.
}

/* Monitoring the Central Manager’s Authorization */
Expand Down
3 changes: 1 addition & 2 deletions core/src/appleMain/kotlin/ScannerBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.juul.kable.logs.Logging
import com.juul.kable.logs.LoggingBuilder
import platform.CoreBluetooth.CBCentralManagerScanOptionAllowDuplicatesKey
import platform.CoreBluetooth.CBCentralManagerScanOptionSolicitedServiceUUIDsKey
import platform.Foundation.NSArray

public actual class ScannerBuilder {

Expand Down Expand Up @@ -36,7 +35,7 @@ public actual class ScannerBuilder {
options[CBCentralManagerScanOptionAllowDuplicatesKey] = it
}
solicitedServiceUuids?.also { uuids ->
options[CBCentralManagerScanOptionSolicitedServiceUUIDsKey] = uuids.map { it.toCBUUID() } as NSArray
options[CBCentralManagerScanOptionSolicitedServiceUUIDsKey] = uuids.map(Uuid::toCBUUID)
}

return CentralManagerCoreBluetoothScanner(
Expand Down

0 comments on commit 3a043a0

Please sign in to comment.