Created
April 22, 2014 23:49
-
-
Save indragiek/11198270 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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