There are lots of pieces you need to take care of:
- You need to wait for the
centralManagerDidUpdateState
to indicateCBCentralManagerStatePoweredOn
. Anything you do before will either result in error or be ignored. So your call toscanForPeripheralsWithServices
is probably ignored. This is true for other APIs, like theretrieveConnectedPeripheralsWithServices
you mentioned. - It is also possible that the device turns off advertising after it is connected, so your scanning will not succeed until you disconnect from it.
- Scanning in the background has many limitations. You can search the SO questions to find out the details. In the beginning I would advise you to not to try backgrounded operation as it can be really tricky.