/phonegap-bluetoothhelper

Helper-Library for Phonegap and Bluetooth Low Energy

Primary LanguageObjective-CGNU General Public License v2.0GPL-2.0

Phonegap-Plugin for Bluetooth Low Energy

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.

Supported platforms

  • iOS

Installing

To use this plugin, add this to your project using the PhoneGap CLI:

phonegap local plugin add https://github.com/CodingRockstar/phonegap-bluetoothhelper.git

Using the event

document.addEventListener('bluetoothUpdateState', 
	function(e) {
		if (e.detail.state == 'CBCentralManagerStatePoweredOff') {
			...
		}
		else if (e.detail.state == 'CBCentralManagerStatePoweredOn') {
			...
		}
		else {
			...
		}
	}, 
	false
);

State-values for Bluetooth-Connection

This event returns the status for the Bluetooth-Connection. These are the same as in CBCentralManagerState (CBCentralManagerState). Possible values are:

  • CBCentralManagerStatePoweredOn
  • CBCentralManagerStatePoweredOff
  • CBCentralManagerStateUnknown
  • CBCentralManagerStateUnsupported
  • ...

Available methods

isEnabled

BluetoothHelper.isEnabled(successCallback, errorCallback); Is Bluetooth enabled (if true call successCallback, else call errorcallback)

Note

The function for checking the Bluetooth-state is taken from https://github.com/don/BluetoothSerial