Originaly forked from Jacob Rosenthal
npm install git+https://git@github.com/Shakarang/react-native-ble
Next see the react native linking guide for visual instructions, but you need to open your project and from node_modules/react-native-estimote drag RNBLE.xcodeproj into your project file browser under Libraries. Then, navigate to your top level project and for your main target, click Build Phases and drag the RNBLE.a Product into the Link Binary With Libraries section. Finally, click the plus button and add CoreBluetooth.framework as well.
It follows the noble api usage.
Only support of following usages on iOS !
var noble = ('react-native-ble');
noble.on('stateChange', function (state) {
if (state === 'poweredOn') {
console.log('Start Scanning');
noble.startScanning([], false);
} else {
noble.stopScanning();
console.log('Stop Scanning');
}
});
noble.on('discover', function (peripheral) {
// Peripheral is an object that was found
});
peripheral.connect(function (error) {
});
When you're connected to a peripheral, you can handle the automatic disconnection by doing :
peripheral.once('disconnect', function () {
});
If you want to disconnect manually :
```javascript
peripheral.disconnect(function (error) {
});
var serviceUUIDs = ["<service UUID 1>", ...];
peripheral.discoverServices(serviceUUIDs, function (error, services) {
});
var service = services[0];
var characteristicsUUIDs = ["<service UUID 1>", ...];
service.discoverCharacteristics(characteristicsUUIDs, function (characteristics) {
});
var characteristic = characteristics[0];
characteristic.read(function (data) {
// Data is a buffer
});
var characteristic = characteristics[0];
characteristic.notify(function (data) {
// Data is a buffer
});