title: Corebluetooth to fetch device names using Swift
body: <p>I'm using CoreBluetooth framework in my iOS application to scan and connect to other bluetooth devices. I'm able to scan successfully for devices using below code:</p>
  
  <pre><code>var centralManager: CBCentralManager?
  var peripherals = [CBPeripheral]()
  centralManager = CBCentralManager(delegate: self, queue: DispatchQueue.main)
  </code></pre>
  
  <p>In the CBCentralManagerDelegate, I implemented below code:</p>
  
  <pre><code>extension ViewController: CBCentralManagerDelegate {
      func centralManagerDidUpdateState(_ central: CBCentralManager) {
          if (central.state == .poweredOn){
              self.centralManager?.scanForPeripherals(withServices: nil, options: nil)
          }
      }
  
      func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
  
          if !peripherals.contains(peripheral) {
              let localName = advertisementData[CBAdvertisementDataLocalNameKey]
              print("\(String(describing: localName))" )
              peripherals.append(peripheral)
              tableView.reloadData()            
          }
      }
  }
  </code></pre>
  
  <p>From above code localName is always nil. Am I missing any code?
  <br><br>
  To add more info,<br>
  When I am scanning for bluetooth devices in my Mac, I'm able to see the names of the devices. But when I am scanning for bluetooth devices on my iPhone, none of them are listed.
  <br><br>
  I cross checked and made sure that I enabled blue tooth on 4 more devices with me (iPad, 2 Android Phones and 1 Android TV)</p>