BLE Fundamentals
Bluetooth Low Energy is designed for low power consumption, making it perfect for IoT devices, fitness trackers, and smart home products. BLE uses a client-server architecture where mobile apps act as Central (client) and devices as Peripheral (server). Understanding GATT (Generic Attribute Profile), Services, and Characteristics is fundamental to BLE development.
iOS CoreBluetooth Framework
CoreBluetooth provides BLE functionality on iOS. Import CoreBluetooth framework, implement CBCentralManagerDelegate for central role, use CBPeripheralDelegate for peripheral interactions, request Bluetooth permissions in Info.plist, and handle Bluetooth state changes (powered on/off, unauthorized).
Always check CBCentralManager state before scanning - attempting operations when Bluetooth is off causes crashes.
Android BLE APIs
Android BLE uses BluetoothAdapter and BluetoothGatt classes. Request BLUETOOTH_SCAN and BLUETOOTH_CONNECT permissions (Android 12+), use BluetoothLeScanner for device discovery, implement BluetoothGattCallback for connection events, and handle location permissions required for BLE scanning.
Device Discovery and Connection
Scan for nearby BLE devices using service UUIDs to filter results. Implement scan timeout (30-60 seconds) to save battery, show RSSI (signal strength) to users, cache discovered devices, and handle duplicate advertisements. Connect to devices with appropriate connection priority based on use case.
GATT Services and Characteristics
GATT defines how data is organized. Services group related characteristics (e.g., Heart Rate Service), characteristics hold actual data values, descriptors provide metadata about characteristics. Read, write, and subscribe to characteristics based on their properties. Use standard Bluetooth SIG UUIDs when possible for interoperability.
Data Transfer Optimization
BLE has limited throughput (about 1 KB/s). Minimize data transfer by sending only changed values, use notifications instead of polling, batch multiple values when possible, compress data before sending, and implement proper flow control to prevent buffer overflow.
Battery and Performance
Optimize battery usage by stopping scans when not needed, using appropriate connection intervals, disconnecting when app goes to background, implementing reconnection logic for dropped connections, and monitoring battery impact with profiling tools.