Skip to content

BMR11/DemoRNBleLiveActivities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

26 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

DemoRNBleLiveActivities

A React Native Expo app demonstrating Bluetooth Low Energy (BLE) communication with iOS Live Activities and Dynamic Island integration. This project showcases how to bridge IoT devices with iOS's real-time notification system using React Native, Expo Targets, and react-native-ble-manager.

DemoRNBleLiveActivities-Video.mov

πŸš€ Features

  • πŸ”΅ Bluetooth Low Energy Integration - Scan, connect, and communicate with BLE devices
  • πŸ“± iOS Live Activities - Real-time device status updates on the lock screen
  • 🏝️ Dynamic Island Support - Compact and expanded views in the Dynamic Island
  • πŸ“Š Real-time Data Sync - Live updates from BLE characteristics to Live Activities
  • πŸ› Comprehensive Debug Logging - Detailed logs for development and troubleshooting
  • ⚑ Expo Targets - Native iOS Live Activity implementation using Expo's target system

🎀 Conference Talk

This repository was used to demonstrate concepts presented at: Seamless BLE to Live Activity Sync in React Native β€” No Push Needed. Presented at React Summit (by GitNation), this talk explores how Bluetooth Low Energy (BLE) can be used to drive real-time UI updates (Live Activities) without relying on network connectivity or push notifications.

πŸ—οΈ Architecture

This app demonstrates a complete BLE-to-LiveActivity pipeline:

BLE Device β†’ React Native App β†’ Live Activity β†’ iOS Lock Screen/Dynamic Island

Key Components

  • BLE Manager: react-native-ble-manager for Bluetooth communication
  • Live Activities: Native iOS implementation using @bacons/apple-targets
  • Real-time Updates: Automatic sync between BLE characteristics and Live Activity state
  • Debug System: Comprehensive logging for development and monitoring

πŸ“± Live Activity Features

The Live Activity displays:

  • Device Status: Connected/Disconnected state with visual indicators
  • Real-time Data: Button state (ON/OFF) and battery level updates
  • Dynamic Island: Compact, expanded, and minimal views
  • Lock Screen: Full widget with device information

πŸ› οΈ Tech Stack

  • React Native 0.81.4
  • Expo SDK 54
  • TypeScript for type safety
  • react-native-ble-manager for BLE communication
  • @bacons/apple-targets for Live Activities
  • Expo Router for navigation
  • iOS Live Activities (ActivityKit)

πŸ“‹ Prerequisites

  • iOS 16.1+ (Live Activities requirement)
  • Xcode 14+ for iOS development
  • Node.js 18+
  • Expo CLI latest version
  • Physical iOS device (Live Activities don't work in simulator)
  • Peripheral Device - You'll need to run a BLE peripheral to test with

πŸš€ Getting Started

1. Clone and Install

git clone https://github.com/BMR11/DemoRNBleLiveActivities.git
cd DemoRNBleLiveActivities
npm install

2. Set Up BLE Peripheral

This demo requires a BLE peripheral device to connect to. You have two options:

Option A: Use the Swift Peripheral App (Recommended)

Clone and run the Swift Core Bluetooth peripheral demo:

# Clone the peripheral app
git clone https://github.com/BMR11/SwiftCoreBluetoothDemo.git
cd SwiftCoreBluetoothDemo
git checkout adding-fake-battery-service

# Open in Xcode
open SwiftCoreBluetoothDemo.xcodeproj
  1. Open the project in Xcode
  2. Run the MyPeripheral target on a physical iOS device
  3. The app will advertise the LBS (Light Button Service) with battery characteristics
  4. This peripheral will simulate button presses and battery level changes

Option B: Use Nordic nRF52 Development Kit

If you have a Nordic nRF52 DK:

  1. Flash the LBS sample code to your nRF52
  2. The device will advertise the required BLE service automatically

3. iOS Setup (Central App)

# Remove existing iOS folder and regenerate
rm -rf ios
npx expo prebuild -p ios

# Start the development server
npx expo start

# Open in Xcode
xed ios

4. Build and Run

  1. Open the project in Xcode
  2. Select your physical iOS device (Live Activities require physical device)
  3. Build and run the app
  4. Grant Bluetooth permissions when prompted
  5. Start the peripheral app on another device
  6. Scan and connect to the peripheral from the central app

πŸ”§ Configuration

BLE Service Configuration

The app is configured to work with a specific BLE service:

const MY_LBS_SERVICE_UUID = "00001523-1212-EFDE-1523-785FEABCD123";
const MY_BUTTON_CHARACTERISTIC_UUID = "00001524-1212-EFDE-1523-785FEABCD123";
const MY_BATTERY_CHARACTERISTIC_UUID = "00001111-1212-EFDE-1523-785FEABCD123";

Live Activity Configuration

The Live Activity is configured in targets/widget/WidgetLiveActivity.swift with:

  • Lock Screen Widget: Full device status display
  • Dynamic Island: Compact and expanded views
  • Real-time Updates: Automatic state synchronization

πŸ“– Usage

Complete Demo Setup

  1. Start the Peripheral (from SwiftCoreBluetoothDemo)

    • Run the MyPeripheral target on a physical iOS device
    • The app will advertise the LBS service with battery characteristics
    • You'll see button and battery simulation controls
  2. Start the Central App (this React Native app)

    • Run the DemoRNBleLiveActivities app on another physical iOS device
    • Grant Bluetooth permissions when prompted

3. Scanning for Devices

  • Tap "Scan for Devices" to discover nearby BLE devices
  • The app will scan for 5 seconds and display found devices
  • Look for the peripheral device from the Swift app
  • Device information includes name, RSSI, and connection status

4. Connecting to a Device

  • Tap on the discovered peripheral device to connect
  • The app will establish a BLE connection and start Live Activity
  • Real-time data will begin flowing from device to Live Activity

5. Testing the Integration

  • Button State: Press/release the button in the peripheral app
  • Battery Level: Use the battery slider in the peripheral app
  • Live Activity Updates: Watch the Live Activity update in real-time
  • Dynamic Island: Check the Dynamic Island for compact updates

6. Monitoring Live Activity

  • Check your iOS lock screen for the Live Activity widget
  • View device status in the Dynamic Island (if available)
  • Real-time updates show button state and battery level

7. Debug Monitoring

  • Use the debug panel at the bottom to monitor BLE communication
  • View detailed logs of all BLE operations and Live Activity updates
  • Clear logs as needed for better monitoring

πŸ” Debug Features

The app includes comprehensive debugging:

  • Real-time Logging: All BLE operations are logged with timestamps
  • Live Activity Tracking: Monitor when Live Activities start/stop/update
  • Connection Status: Track device connection and disconnection events
  • Data Flow: Monitor characteristic value changes and updates

πŸ“ Project Structure

β”œβ”€β”€ app/                          # Expo Router app structure
β”‚   β”œβ”€β”€ (tabs)/
β”‚   β”‚   └── index.tsx            # Main BLE demo screen
β”‚   └── _layout.tsx              # Root layout
β”œβ”€β”€ components/bluetooth/         # BLE-related components
β”‚   β”œβ”€β”€ ConnectedState.tsx       # Connected device UI
β”‚   β”œβ”€β”€ DisconnectedState.tsx    # Device scanning UI
β”‚   └── PeripheralList.tsx       # Device list component
β”œβ”€β”€ targets/widget/              # iOS Live Activity target
β”‚   β”œβ”€β”€ WidgetLiveActivity.swift # Live Activity implementation
β”‚   └── Attributes.swift         # Live Activity data model
β”œβ”€β”€ modules/activity-controller/ # Live Activity management
└── types/bluetooth.ts           # TypeScript definitions

🎯 Key Implementation Details

BLE Integration

  • Uses react-native-ble-manager for cross-platform BLE communication
  • Implements characteristic notifications for real-time data
  • Handles connection state management and error recovery

Live Activities

  • Native iOS implementation using @bacons/apple-targets
  • Supports both Lock Screen widgets and Dynamic Island
  • Real-time updates via ActivityKit

State Management

  • React hooks for BLE state management
  • Real-time Live Activity updates
  • Comprehensive debug logging system

πŸ› Troubleshooting

Common Issues

  1. Live Activity not appearing

    • Ensure you're using a physical iOS device (not simulator)
    • Check that iOS version is 16.1 or later
    • Verify Live Activity permissions in Settings
  2. BLE scanning not working

    • Ensure Bluetooth is enabled
    • Check app permissions for Bluetooth
    • Verify you're using a physical device
  3. Connection failures

    • Check that your BLE device is advertising the correct service UUID
    • Ensure the device is within range
    • Check debug logs for specific error messages

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test on physical iOS device
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments


Built with ❀️ for the React Native community

About

React Native app demonstrating Bluetooth Low Energy communication with iOS Live Activities. Features real-time device status updates, Dynamic Island integration, and comprehensive debug logging

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors