Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joshdholtz/sweettooth-ios-ble
A simplistic, sugarcoated, iOS CoreBluetooth wrapper
https://github.com/joshdholtz/sweettooth-ios-ble
Last synced: 10 days ago
JSON representation
A simplistic, sugarcoated, iOS CoreBluetooth wrapper
- Host: GitHub
- URL: https://github.com/joshdholtz/sweettooth-ios-ble
- Owner: joshdholtz
- Created: 2013-09-24T18:02:35.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2013-09-25T23:50:14.000Z (about 11 years ago)
- Last Synced: 2024-10-11T10:32:33.120Z (about 1 month ago)
- Language: Objective-C
- Homepage:
- Size: 152 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SweetTooth
A simplistic, sugarcoated, iOS CoreBluetooth Wrapper## Let's Get Down To Business
1. Initialize shared SweetToothManager with its own queue and options (Optional)
- By not calling "initSharedManager", SweetToothManager will be called on main thread with no options
2. Add DiscoverPeripheralBlock to SweetToothManager
- This block will executed when peripherals are discovered
3. Start scanning
- You know, it starts scanning for peripherals````objc
// Initialize SweetToothManager
dispatch_queue_t queue = dispatch_queue_create("com.joshholtz.sweettooth", 0);
[SweetToothManager initSharedManager:queue options:nil];
// Set discover peripheral block
[[SweetToothManager sharedManager] addDiscoverPeripheralBlock:^void(CBPeripheral *peripheral, NSDictionary *advertisementData, NSNumber *RSSI) {
NSLog(@"Name - %@", peripheral.name);
// NOTE: Retain this peripheral for future use - peripheral NEEDS to be retained to be connected to otherwise it will be deallocated
}];
// Start scanning for peripherals
[[SweetToothManager sharedManager] start:nil options:@{CBCentralManagerScanOptionAllowDuplicatesKey:@YES }];````
## The Sweetness
We created some helpers for you to make simple tasks... simple
### Read characteristics of a peripheral
````objc
#import "CBPeripheral+SweetTooth.h"
// This is a peripheral that we retain and set in our DiscoverPeripheralBlock
@property (nonatomic, strong) CBPeripheral *somePeripheral;// Reads characteristics from a service - takes service CCUUID, takes and NSArray of characteristic CCUIDs (nil will get all characteristics)
// This method connects peripheral, discovers service, discovers characterists, request update on characteristic values, and disconnects
[_somePeripheral readCharacteristics:[CBUUID UUIDWithString:@"Some-Service-UUUID"] characteristicUUIDs:@[[CBUUID UUIDWithString:@"ed0d5a2e-00cd-4a3c-bd58-31e9e22a9c43"]] block:^(CBPeripheral *peripheral, NSArray *characteristics, NSError *error) {
[characteristics enumerateObjectsUsingBlock:^(CBCharacteristic* characteristic, NSUInteger idx, BOOL *stop) {
// Here is where you would map value to some variable or data object based on the characteristic's UUID
NSLog(@"%@ has value %@", characteristic.UUID.representativeString, characteristic.value);
}];
}];````