Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import CoreBluetooth
let serviceUUID = CBUUID(string: "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")
let service = CBMutableService(type: serviceUUID, primary: true)
/// 1. `CBCentralManager`를 초기화하고,
self.central = CBCentralManager(delegate: self, queue: nil)
/// 2. 사용가능한 상태가 되면 특정 UUID를 가진 서비스를 스캔합니다.
func centralManagerDidUpdateState(central: CBCentralManager) {
if central.state == .PoweredOn {
// 이미 한 번 스캔된 정보라도 계속 스캔합니다.
let options = [CBCentralManagerScanOptionAllowDuplicatesKey: true]
self.central.scanForPeripheralsWithServices([serviceUUID], options: options)
}
}
/// 3. Peripheral이 스캔되면 이 메서드가 호출됩니다.
func centralManager(central: CBCentralManager,
didDiscoverPeripheral peripheral: CBPeripheral,
advertisementData: [String : AnyObject],
RSSI: NSNumber) {
print(advertisementData[CBAdvertisementDataLocalNameKey]) // "전수열"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment