Skip to content

Instantly share code, notes, and snippets.

Created March 27, 2020 09:49
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
// BluetoothManager.swift
import CoreBluetooth
protocol BluetoothManagerDelegate: AnyObject {
func didErrorReceived(manager: NSObject)
func didSensorReceived(data: Data, rssi: Int)
class BluetoothManager: NSObject {
weak var delegate: BluetoothManagerDelegate?
var centralManager: CBCentralManager!
let kCBAdvDataManufacturerData = "kCBAdvDataManufacturerData"
let kCBAdvDataLocalName = "kCBAdvDataLocalName"
init(delegate: BluetoothManagerDelegate) {
self.delegate = delegate
func start() {
self.centralManager = CBCentralManager(delegate: self, queue: DispatchQueue(label: "com.albertopasca.blequeue"))
func stop() {
extension BluetoothManager: CBCentralManagerDelegate {
func centralManagerDidUpdateState(_ central: CBCentralManager) {
if central.state != .poweredOn {
delegate?.didErrorReceived(manager: self)
} else {
centralManager.scanForPeripherals(withServices: nil, options: nil)
func centralManager(_ central: CBCentralManager,
didDiscover peripheral: CBPeripheral,
advertisementData: [String: Any], rssi RSSI: NSNumber) {
print( advertisementData )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment