Skip to content

Instantly share code, notes, and snippets.

@indragiek
Created April 22, 2014 23:49
Show Gist options
  • Save indragiek/11198270 to your computer and use it in GitHub Desktop.
Save indragiek/11198270 to your computer and use it in GitHub Desktop.
// Create an RBTCentralManager
self.manager = [[RBTCentralManager alloc] init];
// Scan and connect to all the peripherals
RACDisposable *disposable = [[[[[self.manager.stateSignal
takeUntilBlock:^BOOL(NSNumber *state) {
return (state.integerValue == CBCentralManagerStatePoweredOn);
}] then:^RACSignal *{
return [self.manager scanForPeripheralsWithServices:nil options:nil];
}] reduceEach:^(CBPeripheral *peripheral, NSDictionary *advertisementData, NSNumber *RSSI) {
return peripheral;
}] flattenMap:^(CBPeripheral *peripheral) {
return [self.manager connectPeripheral:peripheral options:nil];
}] subscribeError:^(NSError *error) {
NSLog(@"Connection error: %@", error);
} completed:^{
NSLog(@"Connected to all the peripherals");
}];
// Disconnect all the peripherals
[disposable dispose];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment