Created
April 17, 2020 03:48
-
-
Save charlesmuchene/f89ac3a2cea3937583065dc66d25a85c to your computer and use it in GitHub Desktop.
iOS as Central
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Initialize central manager, set self as delegate | |
centralManager = CBCentralManager(delegate: self, queue: nil, options: [CBCentralManagerOptionRestoreIdentifierKey: TraceService.CMRestoreIdentifierKey]) | |
// Provide implementation for delegate callback methods | |
extension TraceService: CBCentralManagerDelegate { | |
func centralManager(_ central: CBCentralManager, willRestoreState dict: [String: Any]) { ... } | |
func centralManagerDidUpdateState(_ central: CBCentralManager) { | |
// When .poweredOn, scan for Peripherals | |
} | |
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String: Any], rssi RSSI: NSNumber) { | |
// Filter Peripherals with TraceService UUID in advertisementData | |
// Initiate connection to Peripheral | |
} | |
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) { | |
peripheral.delegate = self | |
peripheral.discoverServices(TraceProfile.SERVICES) | |
} | |
func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?) { ... } | |
func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) { ... } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment