ios – scanForPeripheralsWithServices:在同一外设上返回两次结果

我使用下面的代码

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

扫描外围设备,然后在同一外设上返回两次结果.如何退货?谢谢.

最佳答案 发生这种情况是因为更新了外围设备的名称.在这种情况下,您将再次获得回调.

该主题包含详细说明:http://lists.apple.com/archives/bluetooth-dev/2013/Apr/msg00099.html

积分去Etan Kissling:

The device name is cached by iOS according to a priority list:

  1. Name read from Device name characteristic after a connect
  2. Name from advertising packet
  3. 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.

要处理重复项,您可以使用外设上的isEqualTo:方法检查已经收到的重复项,或使用NSSet存储它们.

点赞