{"id":20325932,"url":"https://github.com/UnlockAgency/Bluetonium","last_synced_at":"2025-08-21T18:33:16.351Z","repository":{"id":44454365,"uuid":"49410787","full_name":"e-sites/Bluetonium","owner":"e-sites","description":"Bluetooth mapping in Swift","archived":false,"fork":false,"pushed_at":"2019-08-13T05:23:11.000Z","size":89,"stargazers_count":165,"open_issues_count":4,"forks_count":15,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-12-15T02:04:57.906Z","etag":null,"topics":["bluetooth","bluetooth-low-energy","carthage","cocoapods","ios","peripherals","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/e-sites.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-11T07:55:30.000Z","updated_at":"2023-10-28T17:33:10.000Z","dependencies_parsed_at":"2022-08-21T02:50:21.365Z","dependency_job_id":null,"html_url":"https://github.com/e-sites/Bluetonium","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-sites%2FBluetonium","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-sites%2FBluetonium/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-sites%2FBluetonium/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/e-sites%2FBluetonium/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/e-sites","download_url":"https://codeload.github.com/e-sites/Bluetonium/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230527866,"owners_count":18240051,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bluetooth","bluetooth-low-energy","carthage","cocoapods","ios","peripherals","swift"],"created_at":"2024-11-14T19:42:18.488Z","updated_at":"2025-08-21T18:33:11.007Z","avatar_url":"https://github.com/e-sites.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Bluetonium: Bluetooth library in Swift](https://raw.githubusercontent.com/e-sites/Bluetonium/assets/Bluetonium.png)\n\nBluetonium is part of the **[E-sites iOS Suite](https://github.com/e-sites/iOS-Suite)**.\n\n---\n\nBluetonium is a Swift Library that makes it easy to communicate with Bluetooth devices.\n\n[![forthebadge](http://forthebadge.com/images/badges/made-with-swift.svg)](http://forthebadge.com) [![forthebadge](http://forthebadge.com/images/badges/built-with-love.svg)](http://forthebadge.com) [![forthebadge](http://forthebadge.com/images/badges/fo-real.svg)](http://forthebadge.com)\n\n[![Build Status](https://travis-ci.org/e-sites/Bluetonium.svg)](https://travis-ci.org/e-sites/Bluetonium)\n[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/Bluetonium.svg)](https://img.shields.io/cocoapods/v/Bluetonium.svg)\n[![codecov](https://codecov.io/gh/e-sites/Bluetonium/branch/master/graph/badge.svg)](https://codecov.io/gh/e-sites/Bluetonium)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Platform](https://img.shields.io/cocoapods/p/Bluetonium.svg?style=flat)](http://cocoadocs.org/docsets/Bluetonium)\n[![Quality](https://apps.e-sites.nl/cocoapodsquality/Bluetonium/badge.svg?003)](https://cocoapods.org/pods/Bluetonium/quality)\n\n## Features\n\n- [x] 🎲 Services and characteristics mapping\n- [x] 👓 Default data transformers\n- [x] 🔧 Reading \u0026 writing to peripherals\n- [x] 🌔 Background mode\n- [x] 📻 Scanning and connecting to peripherals\n- [x] 🦅 Swift 3 \u0026 4\n\n## Requirements\n\n- iOS 8.0+\n- Xcode 7.2+\n\n## Installation\n### [CocoaPods](http://cocoapods.org/)\nAdd the following to your [Podfile](http://guides.cocoapods.org/using/the-podfile.html):\n\n```rb\npod 'Bluetonium'\n```\n\nMake sure that you are integrating your dependencies using frameworks: add `use_frameworks!` to your Podfile. Then run `pod install`.\n\n### [Carthage](https://github.com/Carthage/Carthage)\nAdd the following to your [Cartfile](https://github.com/Carthage/Carthage/blob/master/Documentation/Artifacts.md#cartfile):\n\n```\ngithub \"e-sites/Bluetonium\"\n```\n\nRun `carthage update` and follow the steps as described in Carthage's [README](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application).\n\n\n## Usage\n\n### Get devices\n\nThe `Manager` will handle searching for devices and connecting to them.\n```swift\nimport Bluetonium\n\nlet manager = Manager()\nmanager.delegate = self\nmanager.startScanForDevices()\n```\n\nIf a device is found you will get notified by the `func manager(_ manager: Manager, didFindDevice device: Device)` delegate call. You can also get all found devices in the `foundDevices` array of your manager.\n\n### Connect to a device\n\nConnecting to a device is simple.\n\n```swift\nmanager.connect(with: device)\n```\n\nThe `device` is a device form the `foundDevices` array.\n\n### Create and register a ServiceModel\n\nA `ServiceModel` subclass will represents a Service, all the properties represent the Characteristics.\n\nThis example represents the [Battery Service](https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.battery_service.xml)\n\n```swift\nclass BatteryServiceModel: ServiceModel {\n\tenum Characteristic : String {\n\t\tcase batteryLevel = \"2A19\"\n\t}\n\n\tvar batteryLevel: UInt8 = 0\n\t\n\toverride var serviceUUID:String {\n\t\treturn \"180F\"\n\t}\n\t\n\toverride func mapping(_ map: Map) {\n\t\tbatteryLevel \u003c- map[Characteristic.batteryLevel.rawValue]\n\t}\n\t\n}\n```\n\nRegister a `ServiceModel` subclass. Make sure you do this before the device is actually connected.\n\n```swift\nlet batteryServiceModel = BatteryServiceModel()\n\nfunc manager(_ manager: Manager, willConnectToDevice device: Device) {\n\tdevice.register(serviceModel: batteryServiceModel)\n}\n```\n\n---\n\n### ServiceModel subclass\n\nA `ServiceModel` subclass will represents a Service, all the properties represent the Characteristics.\nInteracting with the peripheral is only possible once the characteristic did became available through the `func characteristicBecameAvailable(withUUID UUID: String)` function.  \nOr when the `serviceReady` boolean is set to `true`.\n\nIt's recommended to create a struct containing static properties of the UUID's along with your `ServiceModel` this way your app doesn't have to hardcode the UUID in different places and prevents errors. (See example: HeartRateServiceModel in project)\n\n#### Reading\n```swift\nbatteryServiceModel.readValue(withUUID: \"2A19\")\n\n// Or with completion\nbatteryServiceModel.readValue(withUUID: \"2A19\") { value in\n\tprint(value)\n}\n```\n\n#### Writing\n```swift\nbatteryServiceModel.batteryLevel = 10\nbatteryServiceModel.writeValue(withUUID: \"2A19\")\n```\n\n#### Custom DataTransformers\n\nIt is possible that your characteristic has a custom data format or has a data format not yet supported. Then you can create your own custom DataTransformer for that property.\n\nThe custom DataTransformer needs to conform to the `DataTransformer` protocol which has two functions.\n\n```swift\nclass HeartRateDataTransformer: DataTransformer {\n    \n    func transform(dataToValue data: Data?) -\u003e MapValue {\n    \t// Used when reading from the characteristic.\n    \t// Transform Data to your property MapValue.\n    }\n    \n    func transform(valueToData value: MapValue?) -\u003e Data {\n    \t// Used when writing to the characteristic.\n    \t// Transform your property MapValue to Data.\n    }\n    \n}\n```\n\nTo register your custom DataTransform you can add it to the mapping function:\n\n```swift\nfunc mapping(_ map: Map) {\n\theartRate \u003c- (map[\"2A37\"], HeartRateDataTransformer())\n}\n```\n\n#### Set notifications for a characteristic\n\nThe `ServiceModel` has a function that will let you register for value changes on the peripheral. When you return `true` for one of you characteristics it will automatically update the property.\n\n```swift\nfunc registerNotifyForCharacteristic(withUUID UUID: String) -\u003e Bool\n```\n\n## Contributions\n\nFeedback is appreciated and pull requests are always welcome. Let's make [this list](https://github.com/e-sites/Bluetonium/graphs/contributors) longer!\n\n## License\n\nBluetonium is released under the MIT license. See LICENSE for details.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FUnlockAgency%2FBluetonium","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FUnlockAgency%2FBluetonium","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FUnlockAgency%2FBluetonium/lists"}