Skip to content

A Bluetooth library that works as an interface/wrapper on top of Apple's Core Bluetooth

License

Notifications You must be signed in to change notification settings

Dario-Gasquez/Bluelips

Repository files navigation

Bluelips

A Bluetooth library that works as an interface/wrapper on top of Apple's Core Bluetooth. If curious about the design behind this library see: Bluelips Library Design.

Requirements

  • iOS 13.0+
  • Swift 5.0+
  • Xcode 12.0+

Install Instructions

Swift Package Manager


NOTE: These instructions are based on Xcode 13.4.1, the steps may deffer for different Xcode versions.


1 . Open your project and add a package dependency as you prefer (for example: right click on the project -> Add Packages or from the project's Package Dependencies tab).

2 . Paste the following in the package URL field:
https://github.com/Dario-Gasquez/Bluelips.git

3 . Follow the instructions until the Bluelips package is added to the project

Once the package was successfully added you should be able to access it by importing the module:

import Bluelips

Usage

Simplest use-case: Start and Scan for peripherals

Before anything else you will need to start the library and scan for devices as the following code excerpt shows:

import Bluelips

let bleServicesManager = BLEServicesManager(withDelegate: self)

// (1) Start the BLE services library: 
// This causes the `stateDidChangeTo(newState: BLEState)` method of the `BLEServicesDelegate` to be called
bleServicesManager.start()

...

// (2) Start scanning for Bluetooth devices:
// You want to do this after `stateDidChangeTo(newState: BLEState)` is called, and you have verified the state is valid for scanning (for example `.poweredOn`). 
bleServicesManager.startScanning()

Detected devices will be notified to the provided BLEServicesDelegate's method: didDiscoverPeripheral(_ blePeripheral: BLEPeripheral). Check DemoApp for additional functionality.


IMPORTANT: Your app will crash if its Info.plist doesn’t include the required usage description keys. To access Core Bluetooth APIs on apps linked on or after iOS 13, include the Privacy – Bluetooth Always Usage Description (NSBluetoothAlwaysUsageDescription) key. In addition you will also need to add the appropriate background mode (Uses Bluetooth LE Accesories) to the app target capabilities, as show here:

BLE-background-mode


Demo App

The DemoApp directory contains a sample application. It provides an example to explore the BLE Library features like:

  • Scan for peripherals
  • Connect to a peripheral
  • See the list of GATT Services and Characteristics provided by the connected peripheral
  • Read, Write and Subscribe/Unsubscribe to a Characteristic

About

A Bluetooth library that works as an interface/wrapper on top of Apple's Core Bluetooth

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages