CombineCoreBluetooth icon indicating copy to clipboard operation
CombineCoreBluetooth copied to clipboard

API MISUSE: <CBCentralManager: 0x1014f8150> can only accept this command while in the powered on state

Open BestKai opened this issue 1 year ago • 1 comments

If I call the scanForPeripherals function immediately after calling let centralManager: CentralManager = .live() , I got the error and cannot receive anything. when i call scanForPeripherals delay some times ,the error is gone and can receive devices

BestKai avatar Dec 04 '24 16:12 BestKai

you need to check the state property on the manager before calling methods on it; if it's not .poweredOn then you need to wait for state changes using the state change publisher before calling anything.

This should be a bit more seamless I agree, but I don't have push access to this repo any longer so it may be some time before someone else can merge a PR. in the meantime it should be possible to use the state change publisher to avoid the misuse warnings.

klundberg avatar Feb 17 '25 01:02 klundberg