Skip to content
Titanium SDK

appcelerator.ble

A collection of API's to connect and communicate with BLE compatible devices via Bluetooth LE

API reference

Compiled from

Modules.BLE

moduleAndroidiPhoneiPadsince 1.0.0

Extends Titanium.Module

Add-on Bluetooth Low Energy module

Using Bluetooth Low Energy module is used to interact with Bluetooth Low Energy (BLE) devices.

You can download the module at appcelerator.ble

  • Note (IOS): Starting iOS 13, it's mandatory for developers to specify the Privacy Usage Description for Bluetooth by including NSBluetoothAlwaysUsageDescription in their tiapp.xml file. Otherwise accessing any Core Bluetooth APIs would lead to a crash. For backward support for older iOS versions, NSBluetoothPeripheralUsageDescription needs to be defined.

  • If your app needs to run in background to perform certain Bluetooth-related tasks, it must declare that it supports a Core Bluetooth background execution mode in tiapp.xml using UIBackgroundModes key

    <key>UIBackgroundModes</key>
    <array>
        [string](api:Global.String)bluetooth-central</string>
        [string](api:Global.String)bluetooth-peripheral</string>
    </array>

bluetooth-central : The app communicates with Bluetooth low energy peripherals using the Core Bluetooth framework. bluetooth-peripheral :The app shares data using the Core Bluetooth framework.

The Apple documentation states that applications are allowed to scan while backgrounded but the scan must specify the service types. wild card scan is not supported in the background.

Note: A detailed information about how to use module in your application, can be found with artifacts at path modules/iphone (platform)/appcelerator.ble/x.y.z (version of module)/documentation/index.html

Properties 99

ADVERT_DATA_KEY_IS_CONNECTABLE

StringiPhoneiPadsince 1.0.0read-only

A Boolean value that indicates whether the advertising event type is connectable.

The value for this key is an Number object. You can use this value to determine whether your app can currently connect to a peripheral.

ADVERT_DATA_KEY_LOCAL_NAME

StringiPhoneiPadsince 1.0.0read-only

The local name of a peripheral.

The value associated with this key is an String.

ADVERT_DATA_KEY_MANUFACTURER_DATA

StringiPhoneiPadsince 1.0.0read-only

The manufacturer data of a peripheral.

The value associated with this key is an TiBuffer object.

ADVERT_DATA_KEY_OVERFLOW_SERVICE_UUIDS

StringiPhoneiPadsince 1.0.0read-only

An array of UUIDs found in the overflow area of the advertisement data.

The value associated with this key is an array of one or more String objects, representing Service UUIDs. Because data stored in this area results from not fitting in the main advertisement, UUIDs listed here are “best effort” and may not always be accurate. For details about the overflow area of advertisement data, see the startAdvertising(_:) method in PeripheralManager.

ADVERT_DATA_KEY_SERVICE_DATA

StringiPhoneiPadsince 1.0.0read-only

A dictionary that contains service-specific advertisement data.

The keys (Strings objects) represent Service UUIDs, and the values (TiBuffer objects) represent service-specific data.

ADVERT_DATA_KEY_SOLICITED_SERVICE_UUIDS

StringiPhoneiPadsince 1.0.0read-only

An array of solicited service UUIDs.

The value associated with this key is an array of one or more String objects, representing Service UUIDs.

ADVERT_DATA_KEY_TX_POWER_LEVEL

StringiPhoneiPadsince 1.0.0read-only

The transmit power of a peripheral.

The value associated with this key is an instance of Number. This key and value are available if the peripheral provides its transmitting power level in its advertising packet. You can calculate the path loss by comparing the RSSI value with the transmitting power level.

ATT_FAILURE

NumberAndroidsince 1.1.0read-only

The ATT command or request failed.

ATT_INSUFFICIENT_ENCRYPTION_ERROR

Numbersince Android 1.1.0, iPhone 1.0.0, iPad 1.0.0read-only

Reading or writing the attribute’s value failed for lack of encryption.

ATT_INVALID_OFFSET_ERROR

Numbersince Android 1.1.0, iPhone 1.0.0, iPad 1.0.0read-only

The specified offset value was past the end of the attribute’s value.

ATT_INVALID_PDU_ERROR

NumberiPhoneiPadsince 1.0.0read-only

The attribute Protocol Data Unit (PDU) is invalid.

ATT_PREPARE_QUEUE_FULL_ERROR

NumberiPhoneiPadsince 1.0.0read-only

The prepare queue is full, as a result of there being too many write requests in the queue.

ATT_READ_NOT_PERMITTED_ERROR

Numbersince Android 1.1.0, iPhone 1.0.0, iPad 1.0.0read-only

The permissions prohibit reading the attribute’s value.

ATT_REQUEST_NOT_SUPPORTED_ERROR

Numbersince Android 1.1.0, iPhone 1.0.0, iPad 1.0.0read-only

The attribute server doesn’t support the request received from the client.

ATT_SUCCESS

Numbersince Android 1.1.0, iPhone 1.0.0, iPad 1.0.0read-only

The ATT command or request successfully completed.

ATT_UNLIKELY_ERROR

NumberiPhoneiPadsince 1.0.0read-only

The ATT request encountered an unlikely error and wasn’t completed.

ATT_UNSUPPORTED_GROUP_TYPE_ERROR

NumberiPhoneiPadsince 1.0.0read-only

The attribute type isn’t a supported grouping attribute as defined by a higher-layer specification.

ATT_WRITE_NOT_PERMITTED_ERROR

Numbersince Android 1.1.0, iPhone 1.0.0, iPad 1.0.0read-only

The permissions prohibit writing the attribute’s value.

AUTHORISATION_STATUS_DENIED

NumberiPhoneiPadsince 1.0.0read-only

A state that indicates the user explicitly denied Bluetooth access for this app.

Value 2

BEACON_PROXIMITY_FAR

NumberiPhoneiPadsince 1.1.0read-only

current state of the device with reference to a region is far

BEACON_PROXIMITY_IMMEDIATE

NumberiPhoneiPadsince 1.1.0read-only

current state of the device with reference to a region is immediate

BEACON_PROXIMITY_NEAR

NumberiPhoneiPadsince 1.1.0read-only

current state of the device with reference to a region is near

BEACON_PROXIMITY_UNKNOWN

NumberiPhoneiPadsince 1.1.0read-only

current state of the device with reference to a region is unknown

CBUUID_CHARACTERISTIC_FORMAT_STRING

StringiPhoneiPadsince 1.0.0read-only

The UUID for the Presentation Format descriptor, as a string. The corresponding value for this descriptor is an NSData object.

Value 2904

CBUUID_CLIENT_CHARACTERISTIC_CONFIGURATION_STRING

Stringsince Android 1.1.0, iPhone 1.0.0, iPad 1.0.0read-only

The UUID for the Client Configuration descriptor, as a string. In iOS, the corresponding value for this descriptor is an NSNumber object. In android, it is a 32 bit uuid.

Value "00002902-0000-1000-8000-00805f9b34fb in android and 2902 in iOS."

CBUUID_L2CAPPSM_CHARACTERISTIC_STRING

Stringsince Android 1.1.0, iPhone 1.0.0, iPad 1.0.0read-only

The PSM of an L2CAP channel associated with the GATT service containing this characteristic.This PSM is a little-endian UInt16. Servers can publish this characteristic with the UUID ABDD3056-28FA-441D-A470-55A75A52553A.

Value 2906

CHARACTERISTIC_PROPERTIES_BROADCAST

Numbersince 1.0.0read-only

A property that indicates the characteristic can broadcast its value using a characteristic configuration descriptor.

Value "1 in android and 0 in iOS."

A property that indicates the characteristic defines additional properties in the extended properties descriptor.A property that indicates the characteristic defines additional properties in the extended properties descriptor.

Value "128 in android and 7 in iOS."

CHARACTERISTIC_PROPERTIES_INDICATE

Numbersince 1.0.0read-only

A property that indicates the peripheral permits notifications of the characteristic’s value, with a response from the central to indicate receipt of the notification.

Value "32 in android and 5 in iOS."

CHARACTERISTIC_PROPERTIES_NOTIFY

Numbersince 1.0.0read-only

A property that indicates the peripheral permits notifications of the characteristic’s value, without a response from the central to indicate receipt of the notification.

Value "16 in android and 4 in iOS."

CHARACTERISTIC_PROPERTIES_READ

Numbersince 1.0.0read-only

A property that indicates a peripheral can read the characteristic’s value.

Value "2 in android and 1 in iOS."

CHARACTERISTIC_PROPERTIES_WRITE

Numbersince 1.0.0read-only

A property that indicates a peripheral can write the characteristic’s value, with a response to indicate that the write succeeded.

Value "8 in android and 3 in iOS."

A property that indicates a peripheral can write the characteristic's value, without a response to indicate that the write succeeded.

Value "4 in android and 2 in iOS."

An option to bridge classic Bluetooth technology profiles, if already connected over Bluetooth Low Energy.

options object key used in Modules.BLE.CentralManager.connectPeripheral. This option tells the system to connect non-GATT profiles on classic Bluetooth devices, if there is a low energy GATT connection to the same device. A true value instructs the system to bring up classic transport profiles when a low energy transport peripheral connects. A false value tells the system not to use the profiles.

CONNECT_PERIPHERAL_OPTIONS_KEY_NOTIFY_ON_CONNECTION

StringiPhoneiPadsince 1.0.0read-only

A Boolean value that specifies whether the system should display an alert when connecting a peripheral in the background.

options object key used in Modules.BLE.CentralManager.connectPeripheral. The value for this key is an Boolean. This key is useful for apps that haven’t specified the bluetooth-central background mode and can’t display their own alert. If more than one app requests a notification for a given peripheral, the one that was most recently in the foreground receives the alert. If the key isn’t specified, the default value is false.

CONNECT_PERIPHERAL_OPTIONS_KEY_NOTIFY_ON_DISCONNECTION

StringiPhoneiPadsince 1.0.0read-only

A Boolean value that specifies whether the system should display an alert when disconnecting a peripheral in the background.

options object key used in Modules.BLE.CentralManager.connectPeripheral. The value for this key is an Boolean. This key is useful for apps that haven’t specified the bluetooth-central background mode and can’t display their own alert. If more than one app requests a notification for a given peripheral, the one that was most recently in the foreground receives the alert. If the key isn’t specified, the default value is false.

CONNECT_PERIPHERAL_OPTIONS_KEY_NOTIFY_ON_NOTIFICATION

StringiPhoneiPadsince 1.0.0read-only

A Boolean value that specifies whether the system should display an alert for any notification sent by a peripheral.

options object key used in Modules.BLE.CentralManager.connectPeripheral. If true, the system displays an alert for all notifications received from a given peripheral while the app is suspended. the default value is false.

CONNECT_PERIPHERAL_OPTIONS_KEY_REQUIRES_ANCS

StringiPhoneiPadsince 1.0.0read-only

An option to require Apple Notification Center Service (ANCS) when connecting a device.

options object key used in Modules.BLE.CentralManager.connectPeripheral.

CONNECT_PERIPHERAL_OPTIONS_KEY_START_DELAY

StringiPhoneiPadsince 1.0.0read-only

An option that indicates a delay before the system makes a connection.

options object key used in Modules.BLE.CentralManager.connectPeripheral. The corresponding value is an Number that indicates the duration of the delay in seconds.

CONNECTION_EVENT_TYPE_PEER_CONNECTED

NumberiPhoneiPadsince 1.0.0read-only

Peer connected event type. This is 'event' type value for CENTREL_MANAGER_EVENT_PERIPHERAL_CONNECTION_EVENT_DID_OCCUR event.

Value 1

CONNECTION_EVENT_TYPE_PEER_DISCONNECTED

NumberiPhoneiPadsince 1.0.0read-only

Peer disconnect event type. This is 'event' type value for CENTREL_MANAGER_EVENT_PERIPHERAL_CONNECTION_EVENT_DID_OCCUR event.

Value 0

Value used to disable notifications or indications for a client configuration descriptor. You may pass this constant to the unsubscribeFromCharacteristic method.

ENABLE_INDICATION_VALUE

Titanium.BufferAndroidsince 1.0.0read-only

Value used to enable indication for a client configuration descriptor. You may pass this constant to the subscribeToCharacteristic method.

ENABLE_NOTIFICATION_VALUE

Titanium.BufferAndroidsince 1.0.0read-only

Value used to enable notification for a client configuration descriptor. You may pass this constant to the subscribeToCharacteristic method.

LOCATION_MANAGER_AUTHORIZATION_STATUS_RESTRICTED

NumberiPhoneiPadsince 1.1.0read-only

This application is not authorized to use location services. Due to active restrictions on location services, the user cannot change this status, and may not have personally denied authorization

MANAGER_STATE_POWERED_OFF

Numbersince 1.0.0read-only

A state that indicates Bluetooth is currently powered off.

Value "10 in android and 4 in iOS."

MANAGER_STATE_POWERED_ON

Numbersince 1.0.0read-only

A state that indicates Bluetooth is currently powered on and available to use.

Value "12 in android and 5 in iOS."

MANAGER_STATE_RESETTING

NumberiPhoneiPadsince 1.0.0read-only

A state that indicates the connection with the system service was momentarily lost.

Value 1

MANAGER_STATE_TURNING_OFF

NumberAndroidsince 1.0.0read-only

One of the possible values returned by the state property. This value indicates that the local Bluetooth adapter is turning off.

Listen for the didUpdateState event to be notified when the local Bluetooth adapter is turning off.

MANAGER_STATE_TURNING_ON

NumberAndroidsince 1.0.0read-only

One of the possible values returned by the state property. This value indicates that the local Bluetooth adapter is turning on.

Listen for the didUpdateState event to be notified when the local Bluetooth adapter is turning on.

MANAGER_STATE_UNAUTHORIZED

NumberiPhoneiPadsince 1.0.0read-only

A state that indicates the application isn’t authorized to use the Bluetooth low energy role.

Value 3

MANAGER_STATE_UNKNOWN

NumberiPhoneiPadsince 1.0.0read-only

The Peripheral and Central manager’s state is unknown

Value 0

MANAGER_STATE_UNSUPPORTED

NumberiPhoneiPadsince 1.0.0read-only

A state that indicates this device doesn’t support the Bluetooth low energy central or client role.

Value 2

PERIPHERAL_STATE_CONNECTING

NumberiPhoneiPadsince 1.0.0read-only

The peripheral is in the process of connecting to the central manager.

Value 1

REGION_STATE_INSIDE

NumberiPhoneiPadsince 1.1.0read-only

The current state of the device with reference to a region is inside

REGION_STATE_OUTSIDE

NumberiPhoneiPadsince 1.1.0read-only

The current state of the device with reference to a region is outside

REGION_STATE_UNKNOWN

NumberiPhoneiPadsince 1.1.0read-only

The current state of the device with reference to a region is unknown

Methods 14

createBeaconIdentityConstraint

iPhoneiPadsince 1.1.0iOS 13.0+

create a constraint that describes the identity caracteristics of a beacon.

Parameters
ParametersTypeDescription
uuidString

UUID associated with the constraint.

majorNumber

Most significant value associated with the constraint. If a major value wasn't specified, this will be nil.

minorNumber

Least significant value associated with the constraint. If a minor value wasn't specified, this will be nil.

createBeaconRegion

iPhoneiPadsince 1.1.0

create Beacon Region.

Parameters
ParametersTypeDescription
uuidString

The value of uuid.

identifierString

The value of beacon identifier.

majorNumber

The value of major.

minorNumber

The value of minor.

createDescriptor

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

create descriptor.

Parameters
ParametersTypeDescription
valueObject

The value of descriptor.

uuidString

The Bluetooth-specific UUID of the descriptor.

permissionNumber

The permission for descriptor. This parameter is only for android. In android, the permissions can be different for characteristic and descriptor. If Characteristic have the read permission then it is only readable and if descriptor have the write permission, then it is only writable.

createMutableCharacteristic

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

create mutable characteristic.

Parameters
ParametersTypeDescription
propertiesArray<Number>

Characteristic properties determine how the characteristic value can be used, or how the descriptor(s) can be accessed.

permissionsArray<Number>

The permissions of the characteristic value.

uuidString

The Bluetooth-specific UUID of the characteristic.

descriptorsArray<Modules.BLE.Descriptor>

An array of the characteristic’s descriptors.

disable

Androidsince 1.0.0

Disables the local Bluetooth adapter.

This method requires bluetooth permissions to successfully work. To check whether these permissions are granted or not, call isBluetoothAndBluetoothAdminPermissionsGranted method. Listen for the didUpdateState event to be notified when the local Bluetooth adapter is turning off.

Returns Boolean

Returns true if the process is initiated successfully or when the bluetooth is already off.

enable

Androidsince 1.0.0

Enables the local Bluetooth adapter.

This method requires bluetooth permissions to successfully work. To check whether these permissions are granted or not, call isBluetoothAndBluetoothAdminPermissionsGranted method. Listen for the didUpdateState event to be notified when the local Bluetooth adapter is turning on.

Returns Boolean

Returns true if the process is initiated successfully or when the bluetooth is already on.

Initializes the module's central manager. This function must be called in an app that acts as a central before any other function can be used.

Parameters
ParametersTypeDescription
showPowerAlertBoolean

A Boolean value that specifies whether the system warns the user if the app instantiates the central manager when Bluetooth service isn’t available.

restoreIdentifierString

A string containing a unique identifier (UID) for the central manager to instantiate.

initPeripheralManager

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

Initializes the module's peripheral manager object. This function must be called in an app that acts as a peripheral before any other function can be used.

Parameters
ParametersTypeDescription
showPowerAlertBoolean

A Boolean value that specifies whether the system warns the user if the app instantiates the peripheral manager when Bluetooth service isn’t available.

restoreIdentifierString

A string containing a unique identifier (UID) for the peripheral manager to instantiate.

isAdvertisingSupported

Androidsince 1.1.0

Determines whether Bluetooth Low Energy Advertising feature is supported on the local Bluetooth device.

Returns Boolean

Returns true if BLE Advertising is supported on the device, false on bluetooth off or if BLE Advertising is not supported.

isEnabled

Androidsince 1.0.0

Determines if Bluetooth is currently enabled and ready for use.

Returns Boolean

Returns true if the local adapter is on.

isSupported

Androidsince 1.0.0

Determines whether Bluetooth Low Energy feature is supported on the local Bluetooth device.

Returns Boolean

Returns true if BLE is supported on the device, false otherwise.

requestPermissions

Androidsince 2.0.0

Displays a dialog requesting bluetooth permissions from the user.

Displays a dialog requesting the BLUETOOTH_ADVERTISE, BLUETOOTH_CONNECT, and BLUETOOTH_SCAN permissions if running on Android 12 or higher. These permission are required by this module to discover devices and to make the app's device discoverable by other devices. On older Android OS versions, a dialog will not be displayed and will instead check if permissions BLUETOOTH and BLUETOOTH_ADMIN are defined in the app's manifest.

The given optional callback argument and returned Promise will provide a success property indicating if permissions were granted or not.

A dialog will not be displayed if permissions have already been granted and will immediately invoke the optional callback and returned promise with a success result.

Parameters
ParametersTypeDescription
callback?Callback<Titanium.Android.RequestPermissionAccessResult>

Function to be invoked indicating if permissions were granted or not.

Returns Promise<Titanium.Android.RequestPermissionAccessResult>

Returns a Promise whose resolved value is equivalent to that passed to the optional callback argument.

Modules.BLE.Beacon

proxyiPhoneiPadsince 1.1.0

Extends Titanium.Proxy

Represents a beacon that was encountered during region monitoring. You do not create instances of this class directly. They will be delivered via the rangedBeacons event.

The Beacon class represents a beacon that was observed during beacon ranging. You do not create instances of this class directly. The region manager (RegionManager) object reports observed beacons to its associated delegate object. The identity of a beacon is defined by its uuid, major, and minor properties. These values are coded into the beacon itself. For a more thorough description of the meaning of those values, see BeaconRegion.

Properties 7

accuracy

Stringsince 1.1.0

Indicates the one sigma horizontal accuracy in meters.

Use this property to differentiate between beacons with the same proximity value. Do not use it to identify a precise location for the beacon. Accuracy values may fluctuate due to RF interference. A negative value in this property signifies that the actual accuracy could not be determined.

major

Numbersince 1.1.0

The value identifying a group of beacons.

minor

Numbersince 1.1.0

The value identifying a specific beacon within a group.

proximity

Numbersince 1.1.0

The relative distance to the beacon.

rssi

Numbersince 1.1.0

The received signal strength of the beacon, measured in decibels.

timestamp

Numbersince 1.1.0iOS 13.0+

The time when this beacon was observed.

uuid

Stringsince 1.1.0iOS 13.0+

The unique ID of the beacons being targeted.

Modules.BLE.BeaconIdentityConstraint

proxyiPhoneiPadsince 1.1.0

Extends Titanium.Proxy

Represents a beacon that was encountered during region monitoring. You do not create instances of this class directly. They will be delivered via the rangedBeacons event.

The Beacon class represents a beacon that was observed during beacon ranging. You do not create instances of this class directly. The region manager (RegionManager) object reports observed beacons to its associated delegate object. The identity of a beacon is defined by its uuid, major, and minor properties. These values are coded into the beacon itself. For a more thorough description of the meaning of those values, see BeaconRegion.

Properties 3

major

Number

The value identifying a group of beacons.

minor

Number

The value identifying a specific beacon within a group.

uuid

String

The unique ID of the beacons being targeted.

Modules.BLE.BeaconRegion

proxyiPhoneiPadsince 1.1.0

Extends Titanium.Proxy

A region used to detect the presence of iBeacon devices.

A BeaconRegion object defines a region that you use to detect Bluetooth beacons conforming to the iBeacon specification.

Properties 5

identifier

Stringsince 1.1.0

This is a value that you specify and can use to identify this region inside your application.

major

Numbersince 1.1.0

The value identifying a group of beacons.

minor

Numbersince 1.1.0

The value identifying a specific beacon within a group.

notifyEntryStateOnDisplay

Numbersince 1.1.0

The relative distance to the beacon. A Boolean indicating whether beacon notifications are sent when the device’s display is on. When set to true, the region manager sends beacon notifications when the user turns on the display and the device is already inside the region. These notifications are sent even if your app is not running. In that situation, the system launches your app into the background so that it can handle the notifications. In both situations, the app will receive a BLE.determinedStateForRegion:event event.

uuid

Stringsince 1.1.0

The unique ID of the beacons being targeted.

Modules.BLE.Central

proxyAndroidiPhoneiPadsince Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

Extends Titanium.Proxy

represent a remote device acting as central, connected to a local app, which is acting as a peripheral.

This class represents remote central devices (or centrals) that have connected to an app implementing the peripheral role on a local device. Remote centrals use universally unique identifiers (UUIDs), to identify themselves. In Android, they have address to identify themselves.

Properties 2

address

Stringsince Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

The address (UUID) of device acting as a central.

maximumUpdateValueLength

NumberiPhoneiPadsince 1.0.0

The maximum amount of data, in bytes, that can be received by the central in a single notification or indication.

Modules.BLE.CentralManager

proxyAndroidiPhoneiPadsince 1.0.0

Extends Titanium.Proxy

An object that scans for, discovers, connects to, and manages peripherals.

CentralManager objects manage discovered or connected remote peripheral devices (represented by Peripheral objects), including scanning for, discovering, and connecting to advertising peripherals.

Properties 3

isScanning

Booleansince 1.0.0

A Boolean value that indicates whether the central is currently scanning.

state

Numbersince 1.0.0read-only

State of the module's internal central manager. For android, it is the current state of the local Bluetooth adapter. Its value is one of the MANAGER_STATE_* constants.

Methods 10

Cancels an active or pending connection to peripheral. Note that this is non-blocking, and any Peripheral commands that are still pending to peripheral may or may not complete.

Parameters
ParametersTypeDescription
peripheralModules.BLE.Peripheral

peripheral object which connnection will be canceled

Returns void

Initiates a connection to peripheral. Connection attempts never time out and, depending on the outcome, will result in a call to either didConnectPeripheral or didFailToConnectPeripheral event. Pending attempts are cancelled automatically upon deallocation of peripheral, and explicitly via Modules.BLE.CentralManager.cancelPeripheralConnection}.

Parameters
ParametersTypeDescription
peripheralModules.BLE.Peripheral

peripheral object to connect

options?Object

This parameter is specific for the iphone, ipad platforms. An optional dictionary specifying connection behavior options. all available dictionary keys are defined as Modules.BLE.CONNECT_PERIPHERAL_OPTIONS_KEY_*

Returns void

createPeripheral

Androidsince 1.0.0

Creates a Modules.BLE.Peripheral class object with the given address.

Parameters
ParametersTypeDescription
addressString

address of the remote bluetooth device.

registerForConnectionEvents

iPhoneiPadsince 1.0.0

Calls connectionEventDidOccur event when a connection event occurs matching any of the given options. Passing nil in the option parameter clears any prior registered matching options.

Parameters
ParametersTypeDescription
peripherals?Array<String>

A list of peripherals UUIDs.

services?Array<String>

A list of services UUIDs.

Returns void

Request for the ACCESS_FINE_LOCATION.

This permission is necessary for the Bluetooth device to scan the nearby BLE devices or other Bluetooth operations.

Returns a list of known peripherals by their identifiers.

Parameters
ParametersTypeDescription
UUIDsArray<String>

A list of peripheral identifiers from which Peripheral objects can be retrieved.

Returns Array<Modules.BLE.Peripheral>

startScan

since 1.0.0

Starts scanning for peripherals.

Parameters
ParametersTypeDescription
services?Array<String>

The UUIDs of services.

options?Modules.BLE.CentralScanOptions

Key/value pairs specifying options for the scan.

2 fields
allowDuplicatesKey Boolean

A Boolean value that specifies whether the scan should run without duplicate filtering.

solicitedServiceUUIDsKey Array<String>

An array of service UUIDs that you want to scan for.

Returns void

stopScan

since 1.0.0

Stops scanning for peripherals.

Returns void

Events 8

connectionEventDidOccur

iPhoneiPadsince 1.0.0

This method is called upon the connection or disconnection of a peripheral that matches any of the options provided in registerForConnectionEventsWithOptions

Event properties
Event propertiesTypeDescription
eventNumber

event value will be Moduels.BLE.CONNECTION_EVENT_TYPE_PEER_DISCONNECTED or Moduels.BLE.CONNECTION_EVENT_TYPE_PEER_CONNECTED

peripheralModules.BLE.Peripheral

object of peripheral.

This event is called when a connection initiated by connectPeripheral has succeeded.

This event is called when a connection initiated by connectPeripheral has succeeded.

Event properties
Event propertiesTypeDescription
peripheralModules.BLE.Peripheral

An object representing the peripheral that connected to the local central manager.

This event is called when a peripheral disconnected.

This event is called upon the disconnection of a peripheral that was connected by connectPeripheral If the disconnection was not initiated by cancelPeripheralConnection, the cause will be detailed in the error parameter. Once this method has been called, no more event will be invoked on peripheral.

Event properties
Event propertiesTypeDescription
peripheralModules.BLE.Peripheral

An object representing the peripheral that disconnected.

errorCodeString

The error code; only present if an error occurred.

errorDomainString

The error domain; only present if an error occurred..

errorDescriptionString

The error description; only peresent if an

A event called when centrel manager discover peripheral

This method is invoked while scanning, upon the discovery of peripheral by central. A discovered peripheral must be retained in order to use it; otherwise, it is assumed to not be of interest and will be cleaned up by the central manager. For a list of discovered peripherals, see peripherals property

Event properties
Event propertiesTypeDescription
peripheralModules.BLE.Peripheral

object of discovered peripheral

didFailToConnectPeripheral

iPhoneiPadsince 1.0.0

This event is called when a connection initiated by connectPeripheral has failed.

This event is called when a connection initiated by connectPeripheral has failed to complete. As connection attempts do not timeout, the failure of a connection is atypical and usually indicative of a transient issue.

Event properties
Event propertiesTypeDescription
peripheralModules.BLE.Peripheral

An object representing the peripheral that failed to connect.

errorCodeString

The error code; only present if an error occurred.

errorDomainString

The error domain; only present if an error occurred..

errorDescriptionString

The error description; only peresent if an

didUpdateANCSAuthorization

iPhoneiPadsince 1.0.0

This event is called when the authorization status changes for a peripheral connected with connectPeripheral with option Modules.BLE.CONNECT_PERIPHERAL_OPTIONS_KEY_REQUIRES_ANCS

Event properties
Event propertiesTypeDescription
peripheralModules.BLE.Peripheral

object of peripheral which disconnected.

didUpdateState

since 1.0.0

A event called when centrel manager state updated

Invoked whenever the central manager's state has been updated. Commands should only be issued when the state is Modules.BLE.MANAGER_STATE_POWERED_ON. A state below Modules.BLE.MANAGER_STATE_POWERED_ON implies that scanning has stopped and any connected peripherals have been disconnected. If the state moves below Modules.BLE.MANAGER_STATE_POWERED_OFF, all Peripheral objects obtained from this central manager become invalid and must be retrieved or discovered again.

Event properties
Event propertiesTypeDescription
stateNumber

state of central manager

willRestoreState

iPhoneiPadsince 1.0.0

A event called when centrel manager will restore state

For apps that opt-in to state preservation and restoration, this is the first event invoked when your app is relaunched into the background to complete some Bluetooth-related task. Use this method to synchronize your app's state with the state of the Bluetooth system.

Event properties
Event propertiesTypeDescription
peripheralsArray<Modules.BLE.Peripheral>

The array contains all of the peripherals connected to the central manager (or had a pending connection) at the time the system terminated the app.

servicesArray<Modules.BLE.Service>

an NSArray of service UUIDs containing all the services the central manager was scanning for at the time the system terminated the app.

optionsArray<Modules.BLE.Service>

The dictionary contains all of the peripheral scan options in use by the central manager when the system terminated the app.

Modules.BLE.Characteristic

proxyiPhoneiPadsince 1.0.0

Extends Titanium.Proxy

A characteristic of a remote peripheral’s service.

It represent the characteristics of a remote peripheral’s service. A characteristic contains a single value and any number of descriptors describing that value. The properties of a characteristic determine how you can use a characteristic’s value, and how you access the descriptors.

Properties 7

A list of the Descriptor* objects that have so far been discovered in this characteristic. It is writeable if this JavaScript object represents a mutable characteristic.

isMutable

Booleansince 1.0.0

Indicates whether this characteristic is mutable.

isNotifying

Booleansince 1.0.0

Whether the characteristic is currently notifying or not.

properties

Numbersince 1.0.0

The properties of the characteristic as a bitfield.

See also CHARACTERISTIC_PROPERTY_* module constants for the possible return values of this property.

uuid

Stringsince 1.0.0

The Bluetooth-specific UUID of the attribute.

Methods 1

equal

since 1.0.0

tests whether two characteristics are same or not.

Parameters
ParametersTypeDescription
characteristicModules.BLE.Characteristic

the characteristic that will be compared.

Returns Boolean

Modules.BLE.Descriptor

pseudoAndroidiPhoneiPadmacOSsince 1.0.0

An object that provides further information about a remote peripheral’s characteristic.

Descriptor objects represent the descriptors of a remote peripheral’s characteristic. Descriptors provide further information about a characteristic’s value. For example, they may describe the value in human-readable form and describe how to format the value for presentation purposes. Characteristic descriptors also indicate whether a characteristic’s value indicates or notifies a client (a central) when the value of the characteristic changes. iOS Note: You must use only one of the two currently supported descriptor types: CBUUID_CHARACTERISTIC_USER_DESCRIPTION_STRING or CBUUID_CHARACTERISTIC_FORMAT_STRING. Reference (https://developer.apple.com/documentation/corebluetooth/cbmutabledescriptor/1518999-init)

Properties 3

uuid

StringAndroidiPhoneiPadsince 1.0.0

The Bluetooth UUID of the descriptor.

value

Titanium.Buffer | String | NumberAndroidiPhoneiPadsince 1.0.0

The value of the descriptor.

The return type of this property varies as per the platform. In iphone and ipad, it can have multiple return type as String, Number and Titanium.Buffer. In android, the return type is Titanium.Buffer only. iOS Note: The descriptor value to cache. You must provide a non-nil value. Once published, you can’t update the value dynamically. Reference (https://developer.apple.com/documentation/corebluetooth/cbmutabledescriptor/1518999-init)

Modules.BLE.DescriptorRequest

proxyAndroidsince 1.1.0

Extends Titanium.Proxy

A request that uses the Attribute Protocol (ATT).

The class represents Attribute Protocol (ATT) read and write requests from remote central devices (represented by Central objects). Remote centrals use these ATT requests to read and write descriptor's values on local peripherals (represented by PeripheralManager objects). Local peripherals, on the other hand, use the properties of Request objects to respond to the read and write requests appropriately, using the respondToDescriptorRequest() method of the PeripheralManager class.

Properties 5

offset

Numbersince 1.1.0read-only

The offset given for the value

responseNeeded

Booleansince 1.1.0read-only

If the remote device requires a response.

If this property is true then user need to call respondToRequest method.

Methods 1

updateValue

since 1.1.0

update the data of value field

Parameters
ParametersTypeDescription
valueTitanium.Buffer

Titanium.Buffer object to update data on value

Returns void

Modules.BLE.L2CAPChannel

proxyAndroidiPhoneiPadsince Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

Extends Titanium.Proxy

L2Cap allow us to open a side channel, with it we can directly read and write without any framing limitation, packet size limitations. It’s a direct way to talk between our devices and accessories.

L2Cap Channel on the lowest level is the stream of data between two devices. It’s actually the protocol that has been used underneath for all types of communication between two devices. So L2Cap has been used from the first day of Bluetooth communications. but now with the L2CAP class, we use is directly talk over these channels.

Properties 2

psm

Numbersince Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

The PSM of the channel.

Methods 4

close

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

closes the l2cap channel

Returns void

getReadBufferSize

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

Get the size of the read buffer in bytes.

Returns Number

Size of the read buffer in bytes.

setReadBufferSize

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

Sets the size of the read buffer in bytes.

You can set the read buffer size at any time, but it will only take effect during the next read. By default, the buffer size is 1024 bytes.

Parameters
ParametersTypeDescription
sizeNumber

The desired size of the read buffer in bytes.

write

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

write data to channel

Parameters
ParametersTypeDescription
dataTitanium.Buffer

Titanium.Buffer object to write data on channel

Returns void

Events 3

onDataReceived

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

Fired whenever new data recived on channel.

Event properties
Event propertiesTypeDescription
dataTitanium.Buffer

Titanium.Buffer object which represent the read data

onStreamError

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

Fired whenever there is some error in reading or writing.

Event properties
Event propertiesTypeDescription
errorCodeString

The error code

errorDomainString

The error domain

errorDescriptionString

The error description

Modules.BLE.MutableCharacteristic

proxyAndroidiPhoneiPadsince Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

Extends Titanium.Proxy

A characteristic of a local peripheral’s service.

It objects represent the characteristics of a local peripheral’s service. This class adds write access to many of the properties in the Characteristic class, which it inherits from.

Properties 2

permissions

NumberiPhoneiPadsince 1.0.0

The permissions of the characteristic value. It is only present if this JavaScript object represents a mutable characteristic.

Modules.BLE.Peer

proxyiPhoneiPadsince 1.0.0

Extends Titanium.Proxy

An object that represents a remote device.

The Peer class is defines common behavior for objects representing remote devices. You typically don’t create instances of either Peer or its concrete subclasses. Instead, the system creates them for you during the process of peer discovery

Properties 1

identifier

Stringsince 1.0.0

The UUID associated with the peer.

Modules.BLE.Peripheral

proxyAndroidiPhoneiPadsince 1.0.0

Extends Titanium.Proxy

A remote peripheral device.

The CBPeripheral class represents remote peripheral devices that your app discovers with a central manager (an instance of CentralManager). In iOS, Peripherals use universally unique identifiers (UUIDs), to identify themselves. For Android, Peripherals use address to be uniqely identified. Peripherals may contain one or more services or provide useful information about their connected signal strength.

Properties 7

address

Stringsince 1.0.0

Once a peripheral has been connected at least once by the system, it is assigned a address (UUID). This address can be stored and later provided to the retrievePeripherals method.

ancsAuthorized

BooleaniPhoneiPadsince 1.0.0iOS 13.0+

A Boolean value that indicates if the remote device has authorization to receive data over ANCS protocol.

canSendWriteWithoutResponse

BooleaniPhoneiPadsince 1.0.0

A Boolean value that indicates whether the remote device can send a write without a response.

isConnected

Booleansince 1.0.0

Whether or not the peripheral is currently connected.

name

Stringsince 1.0.0

The name of the peripheral.

state

NumberiPhoneiPadsince 1.0.0

The current connection state of the peripheral. Possible values defined by PERIPHERAL_STATE_* constants.

Methods 14

Discovers the specified characteristic(s) of a service. The result of this operation is returned via the didDiscoverCharacteristics event. In android, all the characteristics have already been discovered, as part of the discoverServices operation. So, this method is kept in android to keep parity with the iOS platform.

Parameters
ParametersTypeDescription
servicesModules.BLE.Service

The service whose characteristics you want to discover.

characteristicUUIDs?Array<String>

An array of UUID objects that you are interested in. Each UUID identifies the characteristic you want to discover.

Returns void

Discovers the descriptor(s) of a characteristic.The result of this operation is returned via the didDiscoverDescriptorsForCharacteristics event. In android, all the descriptors have already been discovered, as part of the discoverServices operation. So, this method is kept in android to keep parity with the iOS platform.

Parameters
ParametersTypeDescription
characteristicModules.BLE.Characteristic

The characteristic whose descriptors you want to discover.

Returns void

Discovers the specified included service(s) of a service.The result of this operation is returned via the didDiscoverIncludedServices event. In android, all the included services have already been discovered, as part of the discoverServices operation. So, this method is kept in android to keep parity with the iOS platform.

Parameters
ParametersTypeDescription
servicesModules.BLE.Service

The service whose characteristics you want to discover.

includedServiceUUIDs?Array<String>

An array of UUID objects that you are interested in. Each UUID identifies the included service you want to discover.

Returns void

discoverServices

since 1.0.0

Discovers available service(s) on the peripheral. The result of this operation is returned via the didDiscoverServices event.

Parameters
ParametersTypeDescription
serviceUUIDs?Array<String>

An array of UUID objects that you are interested in. Each UUID identifies the services you want to discover. In android, the behavior is discoverServices discovers all the available services irrespective of this parameter.

Returns void

maximumWriteValueLength

iPhoneiPadsince 1.0.0

The maximum amount of data, in bytes, you can send to a characteristic in a single write type.

Parameters
ParametersTypeDescription
characteristicWriteTypeNumber

Values representing the possible write types to a characteristic’s value.

Returns void

openL2CAPChannel

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0iOS 11.0+, Android 10+

Attempts to open an L2CAP channel to the peripheral using the supplied Protocol/Service Multiplexer (PSM).

Parameters
ParametersTypeDescription
psmIdentifierNumber

The PSM of the channel to open.

encryptionRequired?Boolean

The bool can be true if the service requires the link to be encrypted before a stream can be established. false if the service can be used over an unsecured link. This parameter is applicable in android only and the default value is false.

Returns void

readRSSI

since 1.0.0

Retrieves the current RSSI value for the peripheral while connected to the central manager.

Returns void

Reads the value of a characteristic.The result of this operation is returned via the didUpdateValueForCharacteristic event.

Parameters
ParametersTypeDescription
characteristicModules.BLE.Characteristic

The characteristic whose value you want to read.

Returns void

Reads the value of a descriptor. The result of this operation is returned via the didUpdateValueForDescriptor event.

Parameters
ParametersTypeDescription
descriptorModules.BLE.Descriptor

The characteristic descriptor whose value you want to read.

Returns void

requestConnectionPriority

Androidsince 1.0.0

Request the specific connection priority. This method will send connection parameter update request to the remote device.

Parameters
ParametersTypeDescription
connectionPriorityNumber

Connection priority to set. Must be one of CONNECTION_PRIORITY_HIGH, CONNECTION_PRIORITY_BALANCED and CONNECTION_PRIORITY_LOW_POWER.

Returns void

Enables notifications/indications for a characteristic. If the characteristic allows both, notifications will be used.

In Android, subscribing to a characteristic is a two step process in which, first the setCharacteristicNotification() is called which enables the notification locally(on Android device), followed by writing on the descriptor, which is optional. If the second paramater(descriptorUUID) not provided, then writing on the descriptor would not be done. Reference (https://developer.android.com/guide/topics/connectivity/bluetooth-le#notification)

Parameters
ParametersTypeDescription
characteristicModules.BLE.Characteristic

The characteristic whose value you want to read.

descriptorUUID="00002902-0000-1000-8000-00805f9b34fb"?String

The UUID of the configuration descriptor of the characteristic. The module will attempt to write descriptorValue to this descriptor. If you do not want the module to do this, set this parameter to an empty string. This parameter is only for Android.

descriptorValue=ENABLE_NOTIFICATION_VALUE?Titanium.Buffer

The value to be written to the configuration descriptor. This parameter is only for Android.

Returns void

Disables notifications/indications for a characteristic.

Parameters
ParametersTypeDescription
characteristicModules.BLE.Characteristic

The characteristic whose value you want to read.

descriptorUUID="00002902-0000-1000-8000-00805f9b34fb"?String

The UUID of the configuration descriptor of the characteristic. The module will attempt to write descriptorValue to this descriptor. If you do not want the module to do this, set this parameter to an empty string. This parameter is only for Android.

descriptorValue=DISABLE_NOTIFICATION_VALUE?Titanium.Buffer

The value to be written to the configuration descriptor. This parameter is only for Android.

Returns void

Writes a value to a characteristic.

Parameters
ParametersTypeDescription
characteristicModules.BLE.Characteristic

The characteristic whose value you want to write.

dataTitanium.Buffer

The new value of the characteristic.

characteristicWriteTypeNumber

The type of write to be executed. See CHARACTERISTIC_TYPE_WRITE_WITH_RESPONSE and CHARACTERISTIC_TYPE_WRITE_WITHOUT_RESPONSE.

Returns void

Writes the value of a descriptor. The result of this operation is returned via the didWriteValueForDescriptor event.

Writes the value of a characteristic descriptor. This method copies the data passed into the data parameter, and you can dispose of it after the method returns. Note (iOS): You can’t use this method to write the value of a client configuration descriptor (represented by the BLE.CBUUID_CLIENT_CHARACTERISTIC_CONFIGURATION_STRING constant), which describes the configuration of notification or indications for a characteristic’s value. If you want to manage notifications or indications for a characteristic’s value, you must use the subscribeToCharacteristic({characteristic:}) and unsubscribeFromCharacteristic({characteristic:}) method instead. Another Note (iOS): Once published, you can’t update the value dynamically. Reference (https://developer.apple.com/documentation/corebluetooth/cbmutabledescriptor/1518999-init)

Parameters
ParametersTypeDescription
descriptorModules.BLE.Descriptor

The descriptor whose value you want to write.

dataTitanium.Buffer

The new value of the characteristic.

Returns void

Events 14

This event returns the result of a call to the discoverCharacteristics method. If the characteristic(s) were read successfully, they can be retrieved via the service property's characteristics property.

Core Bluetooth invokes this method when your app calls the discoverCharacteristics method. If the peripheral successfully discovers the characteristics of the specified service, you can access them through the service’s characteristics property.

Event properties
Event propertiesTypeDescription
sourcePeripheralModules.BLE.Peripheral

The peripheral providing this information.

serviceModules.BLE.Service

The service to which the characteristics belong.

errorCodeString

The error code; only present if an error occurred.

errorDomainString

The error domain; only present if an error occurred.

errorDescriptionString

The error description; only peresent if an error occurred.

This event returns the result of a call to the discoverDescriptorsForCharacteristic method.

Core Bluetooth invokes this method when your app calls the discoverDescriptors method. If the peripheral successfully discovers the descriptors of the specified characteristic, you can access them through the characteristic’s descriptors property.

Event properties
Event propertiesTypeDescription
sourcePeripheralModules.BLE.Peripheral

The peripheral providing this information.

characteristicModules.BLE.Characteristic

The service to which the characteristics belong.

errorCodeString

The error code; only present if an error occurred.

errorDomainString

The error domain; only present if an error occurred.

errorDescriptionString

The error description; only peresent if an error occurred.

This event returns the result of a call to the discoverIncludedServices method.

Core Bluetooth invokes this method when your app calls the discoverIncludedServices method. If the peripheral successfully discovers services, you can access them through the service’s includedServices property.

Event properties
Event propertiesTypeDescription
sourcePeripheralModules.BLE.Peripheral

The peripheral providing this information.

errorCodeString

The error code; only present if an error occurred.

errorDomainString

The error domain; only present if an error occurred.

errorDescriptionString

The error description; only peresent if an error occurred.

didDiscoverServices

iPhoneiPadsince 1.0.0

Discovers the specified services of the peripheral.

Core Bluetooth invokes this method when your app calls the discoverServices method. If the peripheral successfully discovers services, you can access them through the peripheral’s services property.

Event properties
Event propertiesTypeDescription
sourcePeripheralModules.BLE.Peripheral

The peripheral providing this information.

errorCodeString

The error code; only present if an error occurred.

errorDomainString

The error domain; only present if an error occurred.

errorDescriptionString

The error description; only peresent if an error occurred.

didModifyServices

iPhoneiPadsince 1.0.0

This event is fired when the services of the peripheral change.

Core Bluetooth invokes this method whenever one or more services of a peripheral change. The invalidatedServices parameter includes any changed services that you previously discovered; you can no longer use these services. You can use the discoverServices method to discover any new services that the peripheral added to its database. Use this same method to find out whether any of the invalidated services that you were using (and want to continue using) now have a different location in the peripheral’s database.

Event properties
Event propertiesTypeDescription
sourcePeripheralModules.BLE.Peripheral

The peripheral providing this information.

servicesArray<Modules.BLE.Service>

The services that have been invalidated.

didOpenChannel

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

This method delivers the result of a previous call to openL2CAPChannel.

Delivers the result of an attempt to open an L2CAP channel.

Event properties
Event propertiesTypeDescription
sourcePeripheralModules.BLE.Peripheral

The peripheral sending the event.

channelModules.BLE.L2CAPChannel

A live L2CAP connection to a remote device.

errorCodeString

The error code; only present if an error occurred.

errorDomainString

The error domain; only present if an error occurred.

errorDescriptionString

The error description; only peresent if an error occurred.

didReadRSSI

since 1.0.0

This event returns the result of a call to the readRSSI method.

Core Bluetooth invokes this method when your app calls the readRSSI() method, while the peripheral is connected to the central manager. If successful, the error parameter is nil and the parameter RSSI reports the peripheral’s signal strength, in decibels. If unsuccessful, the error parameter returns the cause of the failure.

Event properties
Event propertiesTypeDescription
sourcePeripheralModules.BLE.Peripheral

The peripheral providing this information.

rssiNumber

value last read

errorCodeString

The error code; only present if an error occurred.

errorDomainString

The error domain; only present if an error occurred.

errorDescriptionString

The error description; only peresent if an error occurred.

didUpdateName

iPhoneiPadsince 1.0.0

This event is fired when the name of the peripheral changes.

Core Bluetooth invokes this method whenever the peripheral’s Generic Access Profile (GAP) device name changes. Since a peripheral device can change its GAP device name, you can implement this method if your app needs to display the current name of the peripheral device.

Event properties
Event propertiesTypeDescription
sourcePeripheralModules.BLE.Peripheral

The peripheral providing this information.

This event returns the result of a call to the subscribeToCharacteristic or unsubscribeFromCharacteristic method.

Core Bluetooth invokes this method when your app calls the subscribeToCharacteristic or unsubscribeFromCharacteristic method.

Event properties
Event propertiesTypeDescription
sourcePeripheralModules.BLE.Peripheral

The peripheral providing this information.

characteristicModules.BLE.Characteristic

The characteristic to subscribe.

isSubscribedBoolean

A Boolean value that specifies whether the didUpdateNotificationStateForCharacteristics event is for subscribe or unsubscribe operation. true, if subscribe and false otherwise.

errorCodeString

The error code; only present if an error occurred.

errorDomainString

The error domain; only present if an error occurred.

errorDescriptionString

The error description; only peresent if an error occurred.

This event is fired after a call to the readValueForCharacteristic method, or upon receipt of a notification/indication.

Core Bluetooth invokes this method when your app calls the readValueForCharacteristic method. A peripheral also invokes this method to notify your app of a change to the value of the characteristic for which the app previously enabled notifications by calling subscribeToCharacteristic or unsubscribeFromCharacteristic method.

Event properties
Event propertiesTypeDescription
sourcePeripheralModules.BLE.Peripheral

The peripheral providing this information.

characteristicModules.BLE.Characteristic

The characteristic containing the value.

errorCodeString

The error code; only present if an error occurred.

errorDomainString

The error domain; only present if an error occurred.

errorDescriptionString

The error description; only peresent if an error occurred.

This event returns the result of a call to the readValueForDescriptor method.

Core Bluetooth invokes this method when your app calls the readValueForDescriptor method.

Event properties
Event propertiesTypeDescription
sourcePeripheralModules.BLE.Peripheral

The peripheral providing this information.

descriptorModules.BLE.Descriptor

The characteristic descriptor containing the value.

errorCodeString

The error code; only present if an error occurred.

errorDomainString

The error domain; only present if an error occurred.

errorDescriptionString

The error description; only peresent if an error occurred.

This event returns the result of a call to the writeValueForCharacteristic method.

Core Bluetooth invokes this method only when your app calls the writeValueForCharacteristic method with the BLE.CHARACTERISTIC_WRYTE_TYPE_WITH_RESPOSNE constant specified as the write type.

Event properties
Event propertiesTypeDescription
sourcePeripheralModules.BLE.Peripheral

The peripheral providing this information.

characteristicModules.BLE.Characteristic

The characteristic containing the value.

errorCodeString

The error code; only present if an error occurred.

errorDomainString

The error domain; only present if an error occurred.

errorDescriptionString

The error description; only peresent if an error occurred.

This event returns the result of a call to the writeValueForDescriptor method.

Core Bluetooth invokes this method when your app calls the writeValueForDescriptor method.

Event properties
Event propertiesTypeDescription
sourcePeripheralModules.BLE.Peripheral

The peripheral sending the event.

descriptorModules.BLE.Descriptor

The object representing the descriptor that was changed.

errorCodeString

The error code; only present if an error occurred.

errorDomainString

The error domain; only present if an error occurred.

errorDescriptionString

The error description; only peresent if an error occurred.

Tells the delegate that a peripheral is again ready to send characteristic updates.

The peripheral calls this delegate method after a failed call to writeValueForCharacteristic, once peripheral is ready to send characteristic value updates.

Event properties
Event propertiesTypeDescription
sourcePeripheralModules.BLE.Peripheral

The peripheral sending the event.

Modules.BLE.PeripheralManager

proxyAndroidiPhoneiPadsince 1.0.0

Extends Titanium.Proxy

An object that manages and advertises peripheral services exposed by this app.

Core Bluetooth uses PeripheralManager objects to manage published services within the local peripheral’s Generic Attribute Profile (GATT) database and to advertise these services to central devices (represented by Central objects). While a service is in the database, any connected central can see and connect to it. That said, if your app hasn’t specified the bluetooth-peripheral background mode, the contents of its services become disabled when it’s in the background or in a suspended state. In this scenario, any remote central trying to access the service’s characteristic value or characteristic descriptors receives an error.

Properties 3

isAdvertising

Booleansince Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

Whether or not the the module's internal peripheral manager is currently advertising data.

peripheralManagerState

Numbersince Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

State of the module's internal peripheral manager. Its value is one of the MANAGER_STATE_* constants.

restoredPeripheralManagerIdentifier

StringiPhoneiPadsince 1.0.0

string the restoration identifier for a peripheral manager object. this is the same string you assigned to the restoreIdentifier parameter of the initPeripheralManager function.

Methods 13

addService

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

Publishes a service and any of its associated characteristics and characteristic descriptors to the local GATT database.

Parameters
ParametersTypeDescription
characteristicsArray<Modules.BLE.Characteristic>

A list of characteristics of a service.

uuidString

The Bluetooth-specific UUID of the attribute.

primaryBoolean

The type of the service (primary or secondary).

Returns Modules.BLE.Service

Object of service which is added.

closePeripheral

Androidsince 1.1.0

This method closes the peripheral.

This method, when called terminate the ongoing advertisement process if any and closes the peripheral. Application should call this method, soon after it is done with the peripheral operations.

Returns void

publishL2CAPChannel

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0iOS 11.0+, Android 10+

Attempts to open an L2CAP channel to the peripheral using the supplied Protocol/Service Multiplexer (PSM).

Parameters
ParametersTypeDescription
encryptionRequiredBoolean

The bool can be true if the service requires the link to be encrypted before a stream can be established. false if the service can be used over an unsecured link.

Returns void

removeAllServices

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

Removes all published services from the local GATT database.

Returns void

removeService

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

Removes a specified published service from the local GATT database.

Parameters
ParametersTypeDescription
serviceModules.BLE.Service

Object of service you want to remove.

Returns void

respondToDescriptorRequest

Androidsince 1.1.0

Used to respond to request(s) received via the didReceiveDescriptorReadRequest or didReceiveDescriptorWriteRequest event.

Parameters
ParametersTypeDescription
descriptorRequestModules.BLE.DescriptorRequest

The request to which the peripheral is responding.

resultNumber

The result code; see the ATT_ERROR* constants.

Returns void

respondToRequest

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

Used to respond to request(s) received via the didReceiveReadRequest or didReceiveWriteRequests event.

Parameters
ParametersTypeDescription
requestModules.BLE.Request

The request to which the peripheral is responding.

resultNumber

The result code; see the ATT_ERROR* constants.

Returns void

setDesiredConnectionLatency

iPhoneiPadsince 1.0.0

Sets the desired connection latency for an existing connection on the module's internal peripheral manager.

Connection latency changes are not guaranteed, so the resultant latency may vary. If a desired latency is not set, the latency chosen by the central at the time of connection establishment will be used. Typically, it is not necessary to change the latency.

Parameters
ParametersTypeDescription
latencyNumber

The desired connection latency. see BLE.PERIPHERAL_MANAGER_CONNECTION_LATENCY_*

centralModules.BLE.Central

A connected central

Returns void

startAdvertising

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

Instructs the module's internal peripheral manager to start advertising.

Important: You must call the initPeripheralManager function first! Supported advertising data types are localName and serviceUUIDs. When in the foreground, an application can utilize up to 28 bytes of space in the initial advertisement data for any combination of the supported advertising data types. If this space is used up, there are an additional 10 bytes of space in the scan response that can be used only for the local name. Note that these sizes do not include the 2 bytes of header information that are required for each new data type. Any service UUIDs that do not fit in the allotted space will be added to a special " overflow" area, and can only be discovered by an iOS device that is explicitly scanning for them. While an application is in the background, the local name will not be used and all service UUIDs will be placed in the "overflow" area. In Android, Before starting the advertisement, user must add the service first. If this is not the case, then this method will not work as expected.

Parameters
ParametersTypeDescription
localNameString | Boolean

The local name of a peripheral. This parameter is of type boolean in android

serviceUUIDsArray<String>

An array of service UUIDs.

Returns void

startAdvertisingBeaconRegion

iPhoneiPadsince 1.1.0

Instructs the module's internal peripheral manager to start advertising for beacon region.

Important: You must call the initPeripheralManager function first!

Parameters
ParametersTypeDescription
measurePower?Number

This is the RSSI of the device observed from one meter in its intended environment.This value is optional, but should be specified to achieve the best ranging performance. If not specified, it will default to a pre-determined value for the device.

beaconRegionModules.BLE.BeaconRegion

Object of Beacon Region.

Returns void

stopAdvertising

since 1.0.0

Instructs the module's internal peripheral manager to stop advertising.

Returns void

unpublishL2CAPChannel

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0iOS 11.0+, Android 10+

The service PSM to be removed from the system.

Parameters
ParametersTypeDescription
PSMNumber

The PSM of the channel along with we can close the particular channel.

Returns void

updateValue

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

Instructs the module's internal peripheral manager to send an updated characteristic value to one or more centrals, via a notification or indication.

Parameters
ParametersTypeDescription
characteristicModules.BLE.MutableCharacteristic

The value of the characteristic.

dataTitanium.Buffer

updated characteristic value.

centralsArray<Modules.BLE.Central>

The list of centrals that need to be updated. If not specified, all subscribed centrals will be updated.

Returns Boolean

True if the update could be sent, otherwise false. In iOS, if false was returned, the readyToUpdateSubscribers event will be fired once space has become available, and the update should be re-sent if so desired. In Android, if there are multiple centrals need to be updated, then for any of the central, if the update could not be sent, it returns false.

Events 14

didAddService

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

This event returns the result of a addService call. If service could not be added, the cause will be detailed in the errorCode, errorDomain, and errorDescription properties.

Event properties
Event propertiesTypeDescription
serviceModules.BLE.Service

An object representing the service that was added.

errorCodeString

The error code; only present if an error occurred.

errorDomainString

The error domain; only present if an error occurred..

errorDescriptionString

The error description; only peresent if an

didOpenL2CAPChannel

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

Tells the delegate that the peripheral manager opened an L2CAP channel.

Event properties
Event propertiesTypeDescription
channelModules.BLE.L2CAPChannel

The channel opened by the manager.

errorCodeString

The error code; only present if an error occurred.

errorDomainString

The error domain; only present if an error occurred..

errorDescriptionString

The error description; only peresent if an

didPublishL2CAPChannel

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

Tells the delegate that the peripheral manager created a listener for incoming L2CAP channel connections.

Event properties
Event propertiesTypeDescription
psmNumber

The Protocol/Service Multiplexer (PSM) of the published channel.

errorCodeString

The error code; only present if an error occurred.

errorDomainString

The error domain; only present if an error occurred..

errorDescriptionString

The error description; only peresent if an

didReceiveReadRequest

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

This event is fired when the module's internal peripheral manager receives a read request.

Event properties
Event propertiesTypeDescription
requestModules.BLE.Request

An object representing the request.

didReceiveWriteRequests

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

This event is fired when the module's internal peripheral manager receives a write request for one or more characteristics.

For every invocation of this method, respondToRequest should be called exactly once. If the requests parameter contains multiple requests, they must be treated as an atomic unit. If the execution of one of the requests would cause a failure, the request and error reason should be provided and none of the requests should be executed.

Event properties
Event propertiesTypeDescription
requestArray<Modules.BLE.Request>

request objects describing the incoming write request

didStartAdvertising

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

This event returns the result of a startAdvertising call. If advertisement could not be started, the cause will be detailed in the errorCode, errorDomain, and errorDescription properties.

Event properties
Event propertiesTypeDescription
errorCodeString

The error code; only present if an error occurred.

errorDomainString

The error domain; only present if an error occurred..

errorDescriptionString

The error description; only peresent if an

didSubscribeToCharacteristic

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

This event is fired when a central configures a characteristic to notify or indicate. It should be used as a cue to start sending updates as the characteristic value changes.

In Android, this event is fired by writing on the Client Configuration UUID (00002902-0000-1000-8000-00805f9b34fb) descriptor for given characteristic by central with descriptor values,BLE.ENABLE_NOTIFICATION_VALUE or BLE.ENABLE_INDICATION_VALUE.

Event properties
Event propertiesTypeDescription
centralModules.BLE.Central

An object representing the central that subscribed.

characteristicModules.BLE.Characteristic

An object representintg the characteristic to which the central subscribed.

didUnpublishL2CAPChannel

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

Tells the delegate that the peripheral manager removed a published service from the local system.

Event properties
Event propertiesTypeDescription
psmNumber

The Protocol/Service Multiplexer (PSM) of the published channel.

errorCodeString

The error code; only present if an error occurred.

errorDomainString

The error domain; only present if an error occurred..

errorDescriptionString

The error description; only peresent if an

didUnsubscribeFromCharacteristic

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

This event is fired when a central removes notifications/indications from a characteristic.

In Android, this event is fired by writing on the Client Configuration UUID (00002902-0000-1000-8000-00805f9b34fb) descriptor for given characteristic by central with value BLE.DISABLE_NOTIFICATION_VALUE

Event properties
Event propertiesTypeDescription
centralModules.BLE.Central

An object representing the central that unsubscribed.

characteristicModules.BLE.Characteristic

An object representintg the characteristic from which the central unsubscribed.

didUpdateState

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

Fired whenever the state of the module's internal peripheral manager changes.

Event properties
Event propertiesTypeDescription
stateNumber

An integer describing the state of the module's internal peripheral manager. See the MANAGER_STATE_* constants.

readyToUpdateSubscribers

iPhoneiPadsince 1.0.0

This event is fired when the module's internal peripheral manager receives a write request for one or more characteristics.This event is fired after a failed call to updateValue, when the module's internal peripheral manager is again ready to send characteristic value updates.

willRestoreState

iPhoneiPadsince 1.0.0

Tells the delegate that the peripheral manager opened an L2CAP channel.

Event properties
Event propertiesTypeDescription
advertisementDataObject

An object (dictionary) containing the data being advertised at the time the application was terminated by the system. See the startAdvertising method for more detail.

servicesArray<String>

Array of uuids of Services

Modules.BLE.RegionManager

proxyiPhoneiPadsince 1.1.0

Extends Titanium.Proxy

An object that manages and scan beacons.

Properties 8

isMonitoringAvailable

Booleanread-only

Determines whether the device supports monitoring for the specified type of region.

If false, all attempts to monitor the specified type of region will fail.

isRangingAvailable

Booleanread-only

Determines whether the device supports ranging.

If false, all attempts to range beacons will fail.

locationServicesEnabled

Booleanread-only

Determines whether the user has location services enabled.

If false, and you proceed to call other CoreLocation API, user will be prompted with the warning dialog. You may want to check this property and use location services only when explicitly requested by the user.

The maximum region size, in terms of a distance from a central point, that the framework can support.

Attempts to register a region larger than this will generate a kCLErrorRegionMonitoringFailure. This value may vary based on the hardware features of the device, as well as on dynamically changing resource constraints.

Retrieve a set of objects for the regions that are currently being monitored.

If manager has been instructed to monitor a region, during this or previous launches of your application, it will be present in this set.

Methods 9

When locationManagerAuthorizationStatus == LOCATION_MANAGER_AUTHORIZATION_STATUS_NOT_DETERMINED, calling this method will start the process of requesting "LOCATION_MANAGER_AUTHORIZATION_STATUS_AUTHORIZED_ALWAYS" authorization from the user.

An application which currently has "LOCATION_MANAGER_AUTHORIZATION_STATUS_AUTHORIZED_WHEN_IN_USE" authorization and has never before requested "LOCATION_MANAGER_AUTHORIZATION_STATUS_AUTHORIZED_ALWAYS" authorization may use this method to request "LOCATION_MANAGER_AUTHORIZATION_STATUS_AUTHORIZED_ALWAYS" authorization one time only. Note: To call this method, you must have both NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription keys in your app’s tiapp.xml file.

<key>NSLocationWhenInUseUsageDescription</key>
[string](api:Global.String)Allow Location permission</string>
<key>NSLocationAlwaysUsageDescription</key>
[string](api:Global.String)Allow Location permission</string>

For More Info: https://developer.apple.com/documentation/corelocation/cllocationmanager/1620551-requestalwaysauthorization

Returns void

Asynchronously retrieve the cached state of the specified region. The state is returned to the "didDetermineState" event

Parameters
ParametersTypeDescription
beaconRegionModules.BLE.BeaconRegion

Beacon region which state is requested

Returns void

When locationManagerAuthorizationStatus == LOCATION_MANAGER_AUTHORIZATION_STATUS_NOT_DETERMINED, calling this method will trigger a prompt to request "LOCATION_MANAGER_AUTHORIZATION_STATUS_AUTHORIZED_WHEN_IN_USE" authorization from the user.

Note: This method runs asynchronously and prompts the user to grant permission to the app to use location services. The user prompt contains the text from the NSLocationWhenInUseUsageDescription key in your tiapp.xml file, and the presence of that key is required when calling this method. The user prompt displays the following options, which determine the authorization your app can receive.

<key>NSLocationWhenInUseUsageDescription</key>
[string](api:Global.String)Allow Location permission</string>
Returns void

Start monitoring the specified region.

If a region of the same type with the same identifier is already being monitored for this application, it will be removed from monitoring. For circular regions, the region monitoring service will prioritize regions by their size, favoring smaller regions over larger regions. Note: This is done asynchronously and may not be immediately reflected in monitoredRegions.

Parameters
ParametersTypeDescription
beaconRegionModules.BLE.BeaconRegion

Beacon region object

Returns void

Stop monitoring the specified region.

It is valid to call stopMonitoring for a region that was registered for monitoring with a different region manager object, during this or previous launches of your application. Note: This is done asynchronously and may not be immediately reflected in monitoredRegions.

Parameters
ParametersTypeDescription
beaconRegionModules.BLE.BeaconRegion

Beacon region object

Returns void

Events 11

Invoked when the authorization status changes for this application.

Event properties
Event propertiesTypeDescription
stateNumber

current authorization value. see LOCATION_MANAGER_AUTHORIZATION_STATUS_* for possible values

Invoked when there's a state transition for a monitored region or in response to a request for state via a call to "requestRegionState"

Event properties
Event propertiesTypeDescription
regionModules.BLE.BeaconRegion

Beacon region object

stateNumber

current state value. see REGION_STATE_* for possible values

Invoked when an any error has occurred.

Event properties
Event propertiesTypeDescription
errorCodeString

The error code; only present if an error occurred.

errorDomainString

The error domain; only present if an error occurred..

errorDescriptionString

The error description; only peresent if any

Invoked when an error has occurred ranging beacons in a region.

Event properties
Event propertiesTypeDescription
beaconConstraintModules.BLE.BeaconIdentityConstraint

Beacon Identity Constraint object

errorCodeString

The error code; only present if an error occurred.

errorDomainString

The error domain; only present if an error occurred..

errorDescriptionString

The error description; only peresent if any

didRange

iOS 13.0+

Invoked when a new set of beacons are available in the specified Beacon Identity Constraint

If beacons is empty, it may be assumed no beacons that match the specified Beacon Identity Constraint are nearby. Similarly if a specific beacon no longer appears in beacons, it may be assumed the beacon is no longer received by the device.

Event properties
Event propertiesTypeDescription
beaconConstraintModules.BLE.BeaconIdentityConstraint

Beacon Identity Constraint object

beaconsArray<Modules.BLE.Beacon>

Beacon objects

Invoked when a new set of beacons are available in the specified region

If beacons is empty, it may be assumed no beacons that match the specified region are nearby. Similarly if a specific beacon no longer appears in beacons, it may be assumed the beacon is no longer received by the device.

Event properties
Event propertiesTypeDescription
regionModules.BLE.BeaconRegion

Beacon region object

beaconsArray<Modules.BLE.Beacon>

Beacon objects

Invoked when an error has occurred monitoring beacons in a region.

Event properties
Event propertiesTypeDescription
regionModules.BLE.BeaconRegion

Beacon region object

errorCodeString

The error code; only present if an error occurred.

errorDomainString

The error domain; only present if an error occurred..

errorDescriptionString

The error description; only peresent if any

Invoked when an error has occurred ranging beacons in a region.

Event properties
Event propertiesTypeDescription
regionModules.BLE.BeaconRegion

Beacon region object

errorCodeString

The error code; only present if an error occurred.

errorDomainString

The error domain; only present if an error occurred..

errorDescriptionString

The error description; only peresent if any

Modules.BLE.Request

proxyAndroidiPhoneiPadsince Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

Extends Titanium.Proxy

A request that uses the Attribute Protocol (ATT).

The class represents Attribute Protocol (ATT) read and write requests from remote central devices (represented by Central objects). Remote centrals use these ATT requests to read and write characteristic values on local peripherals (represented by PeripheralManager objects). Local peripherals, on the other hand, use the properties of Request objects to respond to the read and write requests appropriately, using the respondToRequest() method of the PeripheralManager class.

Properties 5

offset

Numbersince Android 1.1.0, iPhone 1.0.0, iPad 1.0.0read-only

The zero-based index of the first byte for the read or write.

responseNeeded

BooleanAndroidsince 1.1.0read-only

If the remote device requires a response.

If this property is true then user need to call respondToRequest method.

value

Titanium.Buffersince Android 1.1.0, iPhone 1.0.0, iPad 1.0.0read-only

The data being read or written.

Methods 1

updateValue

since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0

update the data of value field

Parameters
ParametersTypeDescription
valueTitanium.Buffer

Titanium.Buffer object to update data on value

Returns void

Modules.BLE.Service

proxyAndroidiPhoneiPadsince 1.0.0

Extends Titanium.Proxy

A collection of data and associated behaviors that accomplish a function or feature of a device.

represent services of a remote peripheral. Services are either primary or secondary and may contain multiple characteristics or included services (references to other services).

Properties 5

isPrimary

Booleansince 1.0.0

A Boolean value that indicates whether the type of service is primary or secondary.

uuid

Stringsince 1.0.0

The Bluetooth-specific UUID of the attribute.