core-bluetoothlisted
Install: claude install-skill thienqo/ios-skills
# Core Bluetooth
Implement Bluetooth Low Energy (BLE) communication on iOS using `CBCentralManager` (connecting to accessories) and `CBPeripheralManager` (advertising as an accessory). Targets Swift 6.4 / iOS 26+.
## Contents
- [Permissions and Background Modes](#permissions-and-background-modes)
- [Central vs Peripheral Roles](#central-vs-peripheral-roles)
- [Core Communication Contract](#core-communication-contract)
- [State Restoration and MTU](#state-restoration-and-mtu)
- [Route by Task](#route-by-task)
- [Common Mistakes](#common-mistakes)
- [Review Checklist](#review-checklist)
- [References](#references)
## Permissions and Background Modes
Declare `NSBluetoothAlwaysUsageDescription` in `Info.plist`. For background execution, enable capabilities in Signing & Capabilities > Background Modes:
- **Uses Bluetooth LE accessories**: Central role in background (`bluetooth-central`)
- **Acts as a Bluetooth LE accessory**: Peripheral role in background (`bluetooth-peripheral`)
```xml
<key>NSBluetoothAlwaysUsageDescription</key>
<string>This app requires Bluetooth to connect to external fitness sensors.</string>
<key>UIBackgroundModes</key>
<array>
<string>bluetooth-central</string>
</array>
```
## Central vs Peripheral Roles
| Feature | Central (`CBCentralManager`) | Peripheral (`CBPeripheralManager`) |
|---|---|---|
| Primary Task | Scans, connects, and consumes GATT services | Publishes services, advertises, responds to requests |
| Discovery | `scanForPeripherals