ScanForPeripheralsWithServices: returns the result twice on the same peripheral

I am using the code below

[centralManager scanForPeripheralsWithServices:serviceUUIDArray options:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:CBCentralManagerScanOptionAllowDuplicatesKey]] 

to scan a perforated device, then the result is returned twice on the same peripheral device. How to return it? Thanks.

+4
source share
1 answer

This is because the peripheral name is being updated. In this case, you will receive a callback again.

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 the priority list:

  • Name read from device name after connection
  • Proposal Name
  • Null

Please note that the name from the proposal must be prefixed with the ending name in the device name specification.

Perhaps the name has already been cached on the physical device and no, send the second update, since it has already received the name.

Your application should be able to handle duplicates, even if you do not ask for them.

To deal with duplicates, you can check the ones already obtained using the isEqualTo: method on the periphery or use NSSet to store them.

+1
source

Source: https://habr.com/ru/post/1498112/


All Articles