This is a helper-library for working with Phonegap (>= 3.0) and Bluetooth Low Energy (BLE). This library has only one method and fires an event, when Bluetooth-state changes.
- iOS
To use this plugin, add this to your project using the PhoneGap CLI:
phonegap local plugin add https://github.com/CodingRockstar/phonegap-bluetoothhelper.git
document.addEventListener('bluetoothUpdateState',
function(e) {
if (e.detail.state == 'CBCentralManagerStatePoweredOff') {
...
}
else if (e.detail.state == 'CBCentralManagerStatePoweredOn') {
...
}
else {
...
}
},
false
);
This event returns the status for the Bluetooth-Connection. These are the same as in CBCentralManagerState
(CBCentralManagerState).
Possible values are:
- CBCentralManagerStatePoweredOn
- CBCentralManagerStatePoweredOff
- CBCentralManagerStateUnknown
- CBCentralManagerStateUnsupported
- ...
BluetoothHelper.isEnabled(successCallback, errorCallback);
Is Bluetooth enabled (if true call successCallback, else call errorcallback)
The function for checking the Bluetooth-state is taken from https://github.com/don/BluetoothSerial