Alberto Sendra
Alberto Sendra

Reputation: 41

didDiscoverPeripheral: not working sometimes on background

Happens both on iOS 12 & iOS 13.

I have Bluetooth-central correctly added on my Info.plist

I'm specifying a list of service UUIDs

What I am seeing:

Upvotes: 2

Views: 413

Answers (1)

Alberto Sendra
Alberto Sendra

Reputation: 41

So, after quite a bit of back and forth between me and our firmware team, we found the reason behind our problems.

Turns out, apps on background when scanning won't read the advertisement extended packet. The problem was, the service UUID we were using to filter the scan for our devices was only being sent on that advertisement extended packet.

For this reason, when the app was scanning a new device, it would not find anything with that service UUID, but once it had found it with the app open, it would cache it internally with its services, and from that point it would work even while on background (because it already knows what services that device has).

The fix was to include that service UUID on the first advertisement packet.

Upvotes: 2

Related Questions