Swift framework for easy connection with Bluetooth peripherals.
Easy to use Bluetooth open source library brought to you by Netguru.
π€ Probably the easiest way to interact with bluetooth peripherals π€
Command
wrapper.Below you can find an easy code sample to connect to the peripheral.
Really thats all that is needed πΎπΎ
let connection = BluetoothConnection.shared
let characteristic = try! Characteristic(uuid: "your_characteristic_uuid", shouldObserveNotification: true)
let service = try! Service(uuid: "your_service_uuid", characteristics: [characteristic])
let configuration = try! Configuration(services: [service], advertisement: "your_advertising_uuid")
let peripheral = Peripheral(configuration: configuration)
connection.connect(peripheral) { error in
// do awesome stuff
}
Below you can find a code sample the setup the iPhone to advertise Bluetooth.
Thatβs all it takes to advertise one service containing one characteristic.
let characteristic = try! Characteristic(uuid: "your_characteristic_uuid")
let service = try! Service(uuid: "your_service_uuid", characteristics: [characteristic])
let configuration = try! Configuration(services: [service], advertisement: "your_service_uuid")
let peripheral = Peripheral(configuration: configuration, advertisementData: [.localName("Test"), .servicesUUIDs("your_service_uuid")])
advertisement.advertise(peripheral: peripheral) { error in
// oh no, something failed in that case
}
Of course data transfer is also possible, both for advertising and connection mode!
Below there are some basic examples, for more please see More usage
section ππ»
let command = Command.utf8String("Hello world")
peripheral.write(command: command, characteristic: someCharacteristic, handler: { error in
// written!
})
peripheral.read(characteristic, handler: { data, error in
// read!
})
let command = Command.int8(3)
advertisement.update(command, characteristic: characteristic) { error in
// data updated!
}
advertisement.writeRequestCallback = { characteristic, data in
// written!
}
For more advanced usage check out documentation page at: https://netguru.github.io/BlueSwift/.
Also feel free to check example project bundled with this repository! π©πΌβπ« π¨πΌβπ«
Itβs a complete app that allows connection and sending text messages between two iPhones.
BlueSwift can be dragβn dropped to the project directory,
but whatβs more important itβs supported by most common dependency management!
Just drop the line below to your Podfile:
pod 'BlueSwift'
(but probably youβd like to pin it to the nearest major release, so pod 'BlueSwift' , '~> 1.1.6'
)
The same as with Cocoapods, insert the line below to your Cartfile:
github 'netguru/BlueSwift'
, or including version - github 'netguru/BlueSwift' ~> 1.1.6
(As all cool open source software, itβsβ¦)
Licensed under MIT license.
Also it would be really nice if you could drop us a line about your usage!! ππ