Class: ScanBeacon::CoreBluetoothScanner

Inherits:
GenericScanner show all
Defined in:
lib/scan_beacon/core_bluetooth_scanner.rb

Instance Attribute Summary

Attributes inherited from GenericScanner

#beacons, #parsers

Instance Method Summary collapse

Methods inherited from GenericScanner

#add_beacon, #add_parser, #detect_beacon, #initialize, #scan

Constructor Details

This class inherits a constructor from ScanBeacon::GenericScanner

Instance Method Details

#each_advertisementObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/scan_beacon/core_bluetooth_scanner.rb', line 4

def each_advertisement
  keep_scanning = true
  CoreBluetooth::scan do
    sleep 0.2
    advertisements = CoreBluetooth::new_adverts
    advertisements.each do |scan|
      if scan[:service_uuid]
        advert = scan[:service_uuid] + scan[:data]
        keep_scanning = false if yield(advert, scan[:device], scan[:rssi], 0x03) == false
      else
        keep_scanning = false if yield(scan[:data], scan[:device], scan[:rssi], 0xff) == false
      end
    end
    if advertisements.empty?
      keep_scanning = false if yield(nil, nil, nil) == false
    end
    keep_scanning
  end
end