title: how to get ManufacturerData from BLE advertisement when scanning for multiple vendors' device
body: <p>I am scanning for BLE peripherals from 2 different manufacturers. I cannot receive advertisements from both devices without scanning for ALL services, which is unacceptable.</p>
  
  <p>When I configure scanForPeripherals(withServices: nil) I receive both advertisements. However, when I scan for specific services (0xF4FD and 0x0275), I do not receive packets from 0x0275 devices.</p>
  
  <ul>
  <li>Vendor 0xF4FD advertises the info I need in the CBAdvertisementDataServiceDataKey.</li>
  <li>Vendor 0x0275 advertises the info I need, but in the CBAdvertisementDataManufacturerDataKey.</li>
  </ul>
  
  <p>So 1 vendor is providing data in the ServiceData while the other is using ManufacturerData.</p>
  
  <p>How do I receive both advertisements without resorting to scanning for ALL peripherals?</p>
  
  <pre><code>if AppDelegate.cbManager?.state == .poweredOn {
  
      // 0xF4FD is VendorA device. 0x0275 is VendorB
      // 0xFDF4 alone collects VendorA devices.
      // 0x7502 alone gets nothing
      // both behave the same as 0xFDF4 alone
      // nil gets everything, but kills the battery and collects unwanted devices
      let svcId1 = CBUUID(string: "0xFDF4")
      let svcId2 = CBUUID(string: "0x7502")
      let desiredServices = [svcId2, svcId1]
      cbManager.scanForPeripherals(withServices: desiredServices, options: nil)
  }
  </code></pre>
  
  <p>... and the receive side...</p>
  
  <pre><code>func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
  
      if let key = advertisementData.keys.first(where: { $0.contains(CBAdvertisementDataServiceDataKey) }), let result = advertisementData[key] {
          print("0xFDF4 peripheral: \(result)")
      }
  
      if let key = advertisementData.keys.first(where: { $0.contains(CBAdvertisementDataManufacturerDataKey) }), let result = advertisementData[key] {
          print("0x7502 peripheral: \(result)")
      }
  }
  </code></pre>
  
  <p>... output ...</p>
  
  <pre><code>0x7502 peripheral: &lt;750200c6 64ff0b01 3e839fcb f863000e ed91&gt;
  0xFDF4 peripheral: {
      FDF4 = &lt;0103fa60 19aaa900 002b51&gt;;
  }
  0xFDF4 peripheral: {
      FDF4 = &lt;0111f31f 6f8fee00 05368d&gt;;
  }
  0x7502 peripheral: &lt;750200c6 64ff0b01 103e1cde a0550005 f545&gt;
  </code></pre>
  
  <p>The receive code successfully extracts the data (if/when it gets data).</p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>The call to scanForPeripherals(withServices: "0xFDF4" ) allows me to scan for only for VendorA's service. This correlates to the 5th byte=<strong>0x16</strong> in the Advertising Packet, (called "Service Data-16-bit UUID" in the BLE Spec).</p>
  
  <p>However, VendorB provides the desired info in the Manufacturer Data, which correlates to Advertising Data=<strong>0xff</strong>. ("Manufacturer Specific Data" in the BLE Spec). It seems the 2 parameters are mutually exclusive: either I can get Service Data <strong>or</strong> Manufacturer Data.</p>
  
  <ul>
  <li>Does that mean that if I want Manufacturer Data, I must scan for ALL services and sift through  all packets from unwanted services??</li>
  <li>Or can I somehow get the Manufacturer Data by subscribing to a Service?</li>
  </ul>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>I've learned that Vendor B does not advertise any services. Also, Advertising Data Type=0xFF  corresponds to the iBeacon format. My question now becomes:</p>
  
  <ul>
  <li>can I scan for Services and iBeacons at the same time?</li>
  </ul>