BluetoothKit
Easily communicate between iOS devices using BLE.
Background
Apple mostly did a great job with the CoreBluetooth API, but because it encapsulated the entire Bluetooth 4.0 LE specification, it can be a lot of work to achieve simple tasks like sending data back and forth between iOS devices, without having to worry about the specification and the inner workings of the CoreBluetooth stack.
BluetoothKit tries to address the challenges this may cause by providing a much simpler, modern, closure-based API all implemented in Swift.
Features
Common
- More concise Bluetooth LE availability definition with enums.
- Bluetooth LE availability observation allowing multiple observers at once.
Central
- Scan for remote peripherals for a given time interval.
- Continuously scan for remote peripherals for a give time interval, with an in-between delay until interrupted.
- Connect to remote peripherals with a given time interval as time out.
- Receive any size of data without having to worry about chunking.
Peripheral
- Start broadcasting with only a single function call.
- Send any size of data to connected remote centrals without having to worry about chunking.
Requirements
- iOS 8.0+ / OSX 10.10+
- Xcode 7.0+
Installation
CocoaPods
CocoaPods is a dependency manager for Cocoa projects.
CocoaPods 0.38.2 is required to build BluetoothKit. It adds support for Xcode 7, Swift 2.0 and embedded frameworks. You can install it with the following command:
To integrate BluetoothKit into your Xcode project using CocoaPods, specify it in your Podfile
:
Then, run the following command:
Carthage
Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.
You can install Carthage with Homebrew using the following command:
To integrate BluetoothKit into your Xcode project using Carthage, specify it in your Cartfile
:
Manual
Add the BluetoothKit project to your existing project and add BluetoothKit as an embedded binary of your target(s).
Usage
Below you find some examples of how the framework can be used. Accompanied in the repository you find an example project that demonstrates a usage of the framework in practice. The example project uses SnapKit and CryptoSwift both of which are great projects. They're bundled in the project and it should all build without further ado.
Common
Make sure to import the BluetoothKit framework in files that use it.
Peripheral
Prepare and start a BKPeripheral object with a configuration holding UUIDs uniqueue to your app(s) and an optional local name that will be broadcasted. You can generate UUIDs in the OSX terminal using the command "uuidgen".
Send data to a connected remote central.
Central
Prepare and start a BKCentral object with a configuration holding the UUIDs you used to configure your BKPeripheral object.
Scan for peripherals for 3 seconds.
Scan continuously for 3 seconds at a time, with an in-between delay of 3 seconds.
Connect a peripheral with a connection attempt timeout of 3 seconds.
License
BluetoothKit is released under the MIT License.