Reputation: 179
I use the below code
[centralManager scanForPeripheralsWithServices:serviceUUIDArray
options:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO]
forKey:CBCentralManagerScanOptionAllowDuplicatesKey]]
to scan a perpheral device, then the result return twice on the same peripheral. How to return one? Thanks.
Upvotes: 4
Views: 1673
Reputation: 16790
This is happening because the peripheral's name is updated. In this case you get the callback once more.
This thread contains a detailed explanation: http://lists.apple.com/archives/bluetooth-dev/2013/Apr/msg00099.html
Credits go to Etan Kissling:
The device name is cached by iOS according to a priority list:
- Name read from Device name characteristic after a connect
- Name from advertising packet
- null
Note that the name from the advertising packet should be a prefix of the final name in the Device name characteristic.
Maybe the physical device already had the name cached, and does not send the second update, as it already retrieved the name.
Your app should be able to deal with duplicates even when you don't request them.
To deal with duplicates, you can check the already received ones with the isEqualTo:
method on the peripheral or use an NSSet
for storing them.
Upvotes: 2