Gormsson
Harald "Bluetooth" Gormsson was a king of Denmark and Norway.
Requirements
- iOS 9.1+
- Xcode 10.2+
Installation
use CocoaPods with Podfile
open your favorite terminal, go to your project root path:
use Carthage with Cartfile
open your favorite terminal, go to your project root path and run:
Usage
Start the service
Gormsson init method let you define a specific queue to avoid being on Main thread
. You can also give an optional Dictionary
for the CoreBluetooth
manager.
Start scan for peripherals
Every peripheral scanned around are return in the didDiscover
block along with the advertisement data. Check the documentation to see all GattAdvertisement
properties available.
In the below example, we filter peripheral that provide the HeartRate
service.
You can custom's advertisement datas variables. See Custom advertisement data.
Connect peripheral
When you connect a peripheral, the library automaticaly stop scan for near peripherals.
Read characteristic
Let's say you want to read the Body Sensor Location
provided by your favorite Heart Rate Monitor sensor, you simply ask the manager to read the .bodySensorLocation
characteristic that will return a value type of BodySensorLocationEnum
.
Subscribe characteristic updates
If you want to get the current Heart Rate and have all updated value, you use the Notify
capability of the characteristic. To achieve this it's as simple as a simply read.
Now any time the value change, the block will be triggered.
Write characteristic
If you want to write value to a characteristic, it's pretty straight forward. You provide the characteristic to be used and the given value to write.
Custom service
In order to use custom service, you just need to create a custom GattService
.
So you can use this custom service to filter the scan peripheral.
Custom characteristic
In order to use custom characteristic class that conforms to CharateristicProtocol
.
Here is an example of a custom characteristc that will provide the number of recorded GPS session.
Then you can use it with read, notify or write BLE command.
Custom advertisement data
In case your BLE peripheral has custom manufacturer data, you can add extension to the GattAdvertisement
class.
Let's say you have the peripheral MAC address provided in the manufacturer data.