{"id":1191,"url":"https://github.com/rhummelmose/BluetoothKit","last_synced_at":"2025-08-06T13:32:38.969Z","repository":{"id":40613969,"uuid":"41428987","full_name":"rhummelmose/BluetoothKit","owner":"rhummelmose","description":"Easily communicate between iOS/OSX devices using BLE","archived":false,"fork":false,"pushed_at":"2023-10-06T13:26:35.000Z","size":1002,"stargazers_count":2271,"open_issues_count":40,"forks_count":267,"subscribers_count":49,"default_branch":"master","last_synced_at":"2024-10-29T17:44:14.301Z","etag":null,"topics":["bluetooth","bluetooth-low-energy","carthage","cocoapods","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rhummelmose.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2015-08-26T14:02:56.000Z","updated_at":"2024-10-25T15:54:58.000Z","dependencies_parsed_at":"2024-01-02T21:08:17.696Z","dependency_job_id":null,"html_url":"https://github.com/rhummelmose/BluetoothKit","commit_stats":null,"previous_names":["rasmusth/bluetoothkit"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhummelmose%2FBluetoothKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhummelmose%2FBluetoothKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhummelmose%2FBluetoothKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rhummelmose%2FBluetoothKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rhummelmose","download_url":"https://codeload.github.com/rhummelmose/BluetoothKit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228905493,"owners_count":17989776,"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","swift"],"created_at":"2024-01-05T20:15:40.912Z","updated_at":"2024-12-09T14:30:57.253Z","avatar_url":"https://github.com/rhummelmose.png","language":"Swift","funding_links":[],"categories":["Hardware","Libs","Swift","第三方库","Hardware [🔝](#readme)","OOM-Leaks-Crash"],"sub_categories":["Bluetooth","Hardware","Other free courses"],"readme":"# BluetoothKit\nEasily communicate between iOS devices using BLE.\n\n[![Build Status](https://travis-ci.org/rhummelmose/BluetoothKit.svg?branch=master)](https://travis-ci.org/rhummelmose/BluetoothKit)\n[![Cocoapods Compatible](https://img.shields.io/cocoapods/v/BluetoothKit.svg)](https://img.shields.io/cocoapods/v/BluetoothKit.svg)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n\n## Background\nApple 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.\n\nBluetoothKit tries to address the challenges this may cause by providing a much simpler, modern, closure-based API all implemented in Swift.\n\n## Features\n\n#### Common\n- More concise Bluetooth LE availability definition with enums.\n- Bluetooth LE availability observation allowing multiple observers at once.\n\n#### Central\n- Scan for remote peripherals for a given time interval.\n- Continuously scan for remote peripherals for a give time interval, with an in-between delay until interrupted.\n- Connect to remote peripherals with a given time interval as time out.\n- Receive any size of data without having to worry about chunking.\n\n#### Peripheral\n- Start broadcasting with only a single function call.\n- Send any size of data to connected remote centrals without having to worry about chunking.\n\n## Requirements\n- iOS 8.0+ / OSX 10.10+\n- Xcode 7.0+\n\n## Installation\n\n#### CocoaPods\n[CocoaPods](http://cocoapods.org) is a dependency manager for Cocoa projects.\n\nCocoaPods 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:\n\n```bash\n$ gem install cocoapods\n```\n\nTo integrate BluetoothKit into your Xcode project using CocoaPods, specify it in your `Podfile`:\n\n```ruby\nsource 'https://github.com/CocoaPods/Specs.git'\nplatform :ios, '8.0'\nuse_frameworks!\n\npod 'BluetoothKit', '~\u003e 0.2.0'\n```\n\nThen, run the following command:\n\n```bash\n$ pod install\n```\n\n#### Carthage\n[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.\n\nYou can install Carthage with [Homebrew](http://brew.sh/) using the following command:\n\n```bash\n$ brew update\n$ brew install carthage\n```\n\nTo integrate BluetoothKit into your Xcode project using Carthage, specify it in your `Cartfile`:\n\n```ogdl\ngithub \"rasmusth/BluetoothKit\" ~\u003e 0.4.0\n```\n\n#### Manual\nAdd the BluetoothKit project to your existing project and add BluetoothKit as an embedded binary of your target(s).\n\n## Usage\n\nBelow 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](https://github.com/SnapKit/SnapKit) and [CryptoSwift](https://github.com/krzyzanowskim/CryptoSwift) both of which are great projects. They're bundled in the project and it should all build without further ado.\n\n#### Common\nMake sure to import the BluetoothKit framework in files that use it.\n```swift\nimport BluetoothKit\n```\n\n#### Peripheral\n\nPrepare 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\".\n```swift\nlet peripheral = BKPeripheral()\nperipheral.delegate = self\ndo {\n\tlet serviceUUID = NSUUID(UUIDString: \"6E6B5C64-FAF7-40AE-9C21-D4933AF45B23\")!\n\tlet characteristicUUID = NSUUID(UUIDString: \"477A2967-1FAB-4DC5-920A-DEE5DE685A3D\")!\n\tlet localName = \"My Cool Peripheral\"\n\tlet configuration = BKPeripheralConfiguration(dataServiceUUID: serviceUUID, dataServiceCharacteristicUUID: \tcharacteristicUUID, localName: localName)\n\ttry peripheral.startWithConfiguration(configuration)\n\t// You are now ready for incoming connections\n} catch let error {\n\t// Handle error.\n}\n```\n\nSend data to a connected remote central.\n```swift\nlet data = \"Hello beloved central!\".dataUsingEncoding(NSUTF8StringEncoding)\nlet remoteCentral = peripheral.connectedRemoteCentrals.first! // Don't do this in the real world :]\nperipheral.sendData(data, toRemoteCentral: remoteCentral) { data, remoteCentral, error in\n\t// Handle error.\n\t// If no error, the data was all sent!\n}\n```\n\n#### Central\nPrepare and start a BKCentral object with a configuration holding the UUIDs you used to configure your BKPeripheral object.\n```swift\nlet central = BKCentral()\ncentral.delegate = self\ncentral.addAvailabilityObserver(self)\ndo {\n\tlet serviceUUID = NSUUID(UUIDString: \"6E6B5C64-FAF7-40AE-9C21-D4933AF45B23\")!\n\tlet characteristicUUID = NSUUID(UUIDString: \"477A2967-1FAB-4DC5-920A-DEE5DE685A3D\")!\n\tlet configuration = BKConfiguration(dataServiceUUID: serviceUUID, dataServiceCharacteristicUUID: characteristicUUID)\n\ttry central.startWithConfiguration(configuration: configuration)\n\t// Once the availability observer has been positively notified, you're ready to discover and connect to peripherals.\n} catch let error {\n\t// Handle error.\n}\n```\n\nScan for peripherals for 3 seconds.\n```swift\ncentral.scanWithDuration(3, progressHandler: { newDiscoveries in\n\t// Handle newDiscoveries, [BKDiscovery].\n}, completionHandler: { result, error in\n\t// Handle error.\n\t// If no error, handle result, [BKDiscovery].\n})\n```\n\nScan continuously for 3 seconds at a time, with an in-between delay of 3 seconds.\n```swift\ncentral.scanContinuouslyWithChangeHandler({ changes, discoveries in\n\t// Handle changes to \"availabile\" discoveries, [BKDiscoveriesChange].\n\t// Handle current \"available\" discoveries, [BKDiscovery].\n\t// This is where you'd ie. update a table view.\n}, stateHandler: { newState in\n\t// Handle newState, BKCentral.ContinuousScanState.\n\t// This is where you'd ie. start/stop an activity indicator.\n}, duration: 3, inBetweenDelay: 3, errorHandler: { error in\n\t// Handle error.\n})\n```\n\nConnect a peripheral with a connection attempt timeout of 3 seconds.\n```swift\ncentral.connect(remotePeripheral: peripherals[indexPath.row]) { remotePeripheral, error in\n\t// Handle error.\n\t// If no error, you're ready to receive data!\n}\n```\n\n## License\nBluetoothKit is released under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhummelmose%2FBluetoothKit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frhummelmose%2FBluetoothKit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frhummelmose%2FBluetoothKit/lists"}