티스토리 뷰

Dev

Dev - iOS에서의 BLE / CoreBluetooth

DevDiana 2026. 1. 7. 10:00

안녕하세요, Diana입니다.

오늘은 저번 글에 이어서 iOS에서의 BLE 와 CoreBluetooth에 대해 알아보려고 합니다.

 


✅ iOS 에서의 BLE 

iOS에서는 Bluetooth 4.0 중 BLE(Bluetooth Low Energy) 기능만을 CoreBluetooth 프레임워크를 통해 제공합니다.
Classic Bluetooth(오디오, HID 등)는 각각 별도의 프레임워크로 분리되어 있으며, CoreBluetooth는 BLE 전용 API입니다.

 

CoreBluetooth에서의 Bluetooth 개념 대응표는 아래와 같습니다.

 

BLE 개념 Corebluetooth 클래스 설명
Central CBCentralManager BLE Central 역할을 담당
Peripheral CBPeripheral BLE Peripheral 디바이스
Advertising scanForPeripherals 주변 Peripheral 탐색
Connection connect(_:options:) Peripheral 연결
GATT CoreBluetooth 자체 Service / Characteristic 구조
Service CBService 기능 단위
Characteristic CBCharacteristic 실제 데이터 단위
Descriptor CBDescriptor Characteristic 부가 정보
UUID CBUUID BLE 식별자

 

✅ 2. CoreBluetooth에서의 BLE 사용

Corebluetooth에서 BLE 통신을 구현하면 아래와 같습니다.

1. Central → CBCentralManager

iOS 디바이스는 BLE 통신에서 항상 Central 역할을 수행합니다.

  • BLE 상태 관리
  • 스캔 시작 / 중지
  • Peripheral 연결 / 해제
  • Bluetooth 전원이 켜졌는지 여부 관리

Bluetooth 상태는 다음 delegate로 전달됩니다.

 

let centralManager = CBCentralManager(delegate: self, queue: nil)

func centralManagerDidUpdateState(_ central: CBCentralManager)

 

2. Peripheral → CBPeripheral

스캔을 통해 발견된 실제 BLE 디바이스를 의미합니다.

  • 광고 데이터 (advertisementData)
  • 신호 세기 (RSSI)
  • 연결 이후 Service / Characteristic 접근 가능

 

func centralManager(
    _ central: CBCentralManager,
    didDiscover peripheral: CBPeripheral,
    advertisementData: [String : Any],
    rssi RSSI: NSNumber
)

3. Advertising → BLE 스캔

BLE Peripheral은 자신을 알리기 위해 Advertising 패킷을 주기적으로 송신합니다.
iOS에서는 이를 스캔을 통해 수신합니다.

  • withServices로 특정 Service UUID 필터 가능
  • 중복 발견 여부 설정 가능

 

centralManager.scanForPeripherals(
    withServices: nil,
    options: [CBCentralManagerScanOptionAllowDuplicatesKey: false]
)

 

4. Connection → Peripheral 연결

centralManager.connect(peripheral, options: nil)

 

연결 성공 시 GATT 기반 통신이 시작됩니다.

 

func centralManager(
    _ central: CBCentralManager,
    didConnect peripheral: CBPeripheral
)

 

5. GATT → Service / Characteristic 탐색

연결 이후에는 GATT 규칙에 따라
Peripheral이 제공하는 데이터를 단계적으로 탐색합니다.

 

Service 탐색

peripheral.discoverServices(nil)
func peripheral(
    _ peripheral: CBPeripheral,
    didDiscoverServices error: Error?
)

 

Characteristic 탐색

peripheral.discoverCharacteristics(nil, for: service)
func peripheral(
    _ peripheral: CBPeripheral,
    didDiscoverCharacteristicsFor service: CBService,
    error: Error?
)

 

6. Service → CBService

  • 하나의 기능 단위
  • 여러 Characteristic을 포함
  • UUID로 식별
let service: CBService

 

 

7. Characteristic → CBCharacteristic

  • 실제 데이터 보관
  • 속성(Properties)에 따라 동작 가능
    • .read
    • .write
    • .notify
    • .indicate
let characteristic: CBCharacteristic

 

 

데이터 읽기

peripheral.readValue(for: characteristic)

 

데이터 쓰기

peripheral.writeValue(
    data,
    for: characteristic,
    type: .withResponse
)

 

값 변경 구독 (Notify)

peripheral.setNotifyValue(true, for: characteristic)

 

8. Descriptor → CBDescriptor

Descriptor는 Characteristic에 대한 부가 설명 정보입니다.

  • 사용자에게 보여줄 문자열
  • 설정 값
peripheral.discoverDescriptors(for: characteristic)

 

9. UUID → CBUUID

BLE의 모든 식별자는 UUID 기반입니다.

 

  • 16-bit UUID (표준)
  • 128-bit UUID (커스텀)
let serviceUUID = CBUUID(string: "180F") // Battery Service

 

 

 

여기까지 iOS의 BLE 통신 Flow를 정리해보면 아래와 같습니다.

 

Bluetooth ON -> CBCentralManager 생성 -> Peripheral Scan -> Peripheral 발견 -> 연결 -> Service 탐색 -> Characteristic 탐색 -> Read / Write / Notify

 

 

이렇게 오늘은 iOS에서의 BLE 통신과 Corebluetooth에 대해 알아보았습니다.

감사합니다.

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2026/04   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30
글 보관함