title: CoreBluetooth advertising detection time
body: <p>This issue has been discussed back in October <a href="https://stackoverflow.com/questions/12866551/corebluetooth-connection-setup-time-varies-quite-a-bit/14090354#14090354">here</a>. This is a new question as CoreBluetooth is fairly new and some changes might have occurred since then.</p>
  
  <p>I have a BLE device advertising every 2 seconds. Scanning is initiated using: </p>
  
  <pre><code>[self.CM scanForPeripheralsWithServices:nil options:0]
  </code></pre>
  
  <p>Which returns most often (via the centralManager didDiscoverPeripheral callback) around 2s to 4s later. (CM is my CentralManger)</p>
  
  <p>However, about 30% of the time, the scan takes 10 to 18 seconds. 
  WiFi and BT in nearby devices has been disabled to clear the spectrum as much as possible.
  The time to scan seems unrelated to RSSI. Which is -40dB when next to the iPAd3, -70dB when about 5 metres away in another room.</p>
  
  <pre><code>[self.CM stopScan]; 
  </code></pre>
  
  <p>is called before the scanWithPeripherals as it reduces the occurrence of really long waits.</p>
  
  <p>No connection is being made. No characteristic or services data is being requested. Advertising data is sufficient.</p>
  
  <p>There is a useful TI <a href="http://processors.wiki.ti.com/index.php/Category%3aIPhone4SBLEDemo#App_Operation" rel="nofollow noreferrer">demonstrator app</a>. 
  This gives similar results (actually slightly worse as it doesn't make any stopScan calls)</p>
  
  <p>The CBCentralManagerScanOptionAllowDuplicatesKey option as seen in this <a href="https://stackoverflow.com/questions/11557500/corebluetooth-central-manager-callback-diddiscoverperipheral-twice">Stackoverflow answer</a> if anything seems to lengthen discovery times.</p>
  
  <p>Obviously, the next step is to use some more advanced BT sniffer / advert generation tools to further characterise this CoreBluetooth response.</p>
  
  <p>This is another useful <a href="https://stackoverflow.com/questions/9896562/what-exactly-can-corebluetooth-applications-do-whilst-in-the-background/10096244#10096244">SO question</a>, but does not elaborate enough on response times.</p>