Swiftpack.co - Dario-Gasquez/Bluelips as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Dario-Gasquez.
Dario-Gasquez/Bluelips 0.1.0
A Bluetooth library that works as an interface/wrapper on top of Apple's Core Bluetooth
⭐️ 0
🕓 1 week ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/Dario-Gasquez/Bluelips.git", from: "0.1.0")

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

GitHub

link
Stars: 0
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

Release 0.1.0
1 week ago

Included in this first release:

  • Implemented the following services:
    • Peripheral scanning
    • Peripheral connection/disconnection
    • See the list of GATT Services and Characteristics provided by the connected peripheral
    • Read, Write and Subscribe/Unsubscribe to a Characteristic
  • Demo application: shows the mentioned services at work.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics