appcelerator.ble
A collection of API's to connect and communicate with BLE compatible devices via Bluetooth LE
Install
A module is a zip you unpack in your project. There is no installer command yet - a ti module install is planned but does not exist today, so the steps below are the ones that work.
1. Download the release archive
2. Unpack it at your project root
cd /path/to/your-project unzip ~/Downloads/appcelerator.ble-iphone-3.0.0.zipThe archive already contains the full path, so it lands in place:
- modules/iphone/appcelerator.ble/3.0.0/
3. Add it to
tiapp.xml<modules> <module platform="iphone" version="3.0.0">appcelerator.ble</module> </modules>The
platformattribute is the packager’s name for the platform, which isiphonefor iOS - the same word the archive uses in its own path.4. Require it from your app
const mod = require('appcelerator.ble');
Manifest
iOS 3.0.0
- Minimum SDK
- 12.0.0
- Module API version
- 2
- Architectures
- arm64, x86_64
- GUID
- 8d0b486f-27ff-4029-a989-56e4a6755e6f
- Author
- Axway
- License
- Proprietary
- Copyright
- Copyright (c) 2020 by Axway Appcelerator
- Mac Catalyst
- not supported
API reference
Compiled from tidev/appcelerator.ble@3.0.0 (51574b4).
Modules.BLE
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
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.
The local name of a peripheral.
The value associated with this key is an String.
The manufacturer data of a peripheral.
The value associated with this key is an TiBuffer object.
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.
A dictionary that contains service-specific advertisement data.
The keys (Strings objects) represent Service UUIDs, and the values (TiBuffer objects) represent service-specific data.
An array of service UUIDs.
The value associated with this key is an ArrayString object.
An array of solicited service UUIDs.
The value associated with this key is an array of one or more String objects, representing Service UUIDs.
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.
The attribute wasn’t found within the specified attribute handle range.
The ATT read blob request can’t read or write the attribute.
The ATT command or request failed.
Reading or writing the attribute’s value failed for lack of authentication.
Reading or writing the attribute’s value failed for lack of authorization.
Reading or writing the attribute’s value failed for lack of encryption.
The encryption key size used for encrypting this link is insufficient.
Resources are insufficient to complete the ATT request.
ATT_INVALID_ATTRIBUTE_VALUE_LENGTH_ERROR
Numbersince Android 1.1.0, iPhone 1.0.0, iPad 1.0.0read-onlyThe length of the attribute’s value is invalid for the intended operation.
The attribute handle is invalid on this peripheral.
The specified offset value was past the end of the attribute’s value.
The attribute Protocol Data Unit (PDU) is invalid.
The prepare queue is full, as a result of there being too many write requests in the queue.
The permissions prohibit reading the attribute’s value.
The attribute server doesn’t support the request received from the client.
The ATT command or request successfully completed.
The ATT request encountered an unlikely error and wasn’t completed.
The attribute type isn’t a supported grouping attribute as defined by a higher-layer specification.
The permissions prohibit writing the attribute’s value.
A state that indicates the user has authorized Bluetooth at any time.
Value 3
A state that indicates the user explicitly denied Bluetooth access for this app.
Value 2
A state that indicates the user has yet to authorize Bluetooth for this app.
Value 0
A state that indicates this app isn’t authorized to use Bluetooth.
Value 1
current state of the device with reference to a region is far
current state of the device with reference to a region is immediate
current state of the device with reference to a region is near
current state of the device with reference to a region is unknown
The UUID for the Aggregate Format descriptor, as a string.
Value 2905
The UUID for the Extended Properties descriptor, as a string. The corresponding value for this descriptor is an NSNumber object.
Value 2900
The UUID for the Presentation Format descriptor, as a string. The corresponding value for this descriptor is an NSData object.
Value 2904
The UUID for the User Description descriptor, as a string. The corresponding value for this descriptor is an NSString object.
Value 2901
CBUUID_CLIENT_CHARACTERISTIC_CONFIGURATION_STRING
Stringsince Android 1.1.0, iPhone 1.0.0, iPad 1.0.0read-onlyThe 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."
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
The UUID for the Server Configuration descriptor, as a string. The corresponding value for this descriptor is an NSNumber object.
Value 2903
A permission that indicates only trusted devices can read the attribute’s value.
Value 2
A permission that indicates a peripheral can read the attribute’s value.
Value "1 in android and 0 in iOS."
A permission that indicates only trusted devices can write the attribute’s value.
Value "32 in android and 3 in iOS."
A permission that indicates a peripheral can write the attribute’s value.
Value "16 in android and 1 in iOS."
A property that indicates the perhipheral allows signed writes of the characteristic’s value, without a response to indicate the write succeeded.
Value 6
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."
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."
A property that indicates only trusted devices can enable indications of the characteristic’s value.
Value 9
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."
A property that indicates that only trusted devices can enable notifications of the characteristic’s value.
Value 8
A property that indicates a peripheral can read the characteristic’s value.
Value "2 in android and 1 in iOS."
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."
Write a characteristic value, without any response from the peripheral to indicate whether the write was successful.
Write a characteristic value, with a response from the peripheral to indicate whether the write was successful.
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.
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.
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.
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.
An option to require Apple Notification Center Service (ANCS) when connecting a device.
options object key used in Modules.BLE.CentralManager.connectPeripheral.
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.
Peer connected event type. This is 'event' type value for CENTREL_MANAGER_EVENT_PERIPHERAL_CONNECTION_EVENT_DID_OCCUR event.
Value 1
Peer disconnect event type. This is 'event' type value for CENTREL_MANAGER_EVENT_PERIPHERAL_CONNECTION_EVENT_DID_OCCUR event.
Value 0
Connection parameter recommended by the Bluetooth SIG.
For a high priority, low latency connection.
For a low power, reduced data rate connection.
A read permission for descriptor.
An encrypted read permission for descriptor.
A write permission for descriptor.
An encrypted write permission for descriptor.
Value used to disable notifications or indications for a client configuration descriptor. You may pass this constant to the unsubscribeFromCharacteristic method.
Value used to enable indication for a client configuration descriptor. You may pass this constant to the subscribeToCharacteristic method.
Value used to enable notification for a client configuration descriptor. You may pass this constant to the subscribeToCharacteristic method.
User has granted authorization to use their location only while they are using your app.
Write a characteristic value, with a response from the peripheral to indicate whether the write was successful.
User has explicitly denied authorization for this application, or location services are disabled in Settings.
User has not yet made a choice with regards to this application
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
A state that indicates Bluetooth is currently powered off.
Value "10 in android and 4 in iOS."
A state that indicates Bluetooth is currently powered on and available to use.
Value "12 in android and 5 in iOS."
A state that indicates the connection with the system service was momentarily lost.
Value 1
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.
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.
A state that indicates the application isn’t authorized to use the Bluetooth low energy role.
Value 3
The Peripheral and Central manager’s state is unknown
Value 0
A state that indicates this device doesn’t support the Bluetooth low energy central or client role.
Value 2
A latency setting that prioritizes extending battery life over rapid communication.
A latency setting indicating that prioritizes rapid communication over battery life.
A latency setting that balances communication frequency and battery life.
The peripheral is connected to the central manager.
Value 2
The peripheral is in the process of connecting to the central manager.
Value 1
The peripheral isn’t connected to the central manager.
Value 0
The peripheral is disconnecting from the central manager.
Value 3
The current state of the device with reference to a region is inside
The current state of the device with reference to a region is outside
The current state of the device with reference to a region is unknown
Methods 14
create a constraint that describes the identity caracteristics of a beacon.
| Parameters | Type | Description |
|---|---|---|
| uuid | String | UUID associated with the constraint. |
| major | Number | Most significant value associated with the constraint. If a major value wasn't specified, this will be nil. |
| minor | Number | Least significant value associated with the constraint. If a minor value wasn't specified, this will be nil. |
create Beacon Region.
| Parameters | Type | Description |
|---|---|---|
| uuid | String | The value of uuid. |
| identifier | String | The value of beacon identifier. |
| major | Number | The value of major. |
| minor | Number | The value of minor. |
createDescriptor
since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0create descriptor.
| Parameters | Type | Description |
|---|---|---|
| value | Object | The value of descriptor. |
| uuid | String | The Bluetooth-specific UUID of the descriptor. |
| permission | Number | 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.0create mutable characteristic.
| Parameters | Type | Description |
|---|---|---|
| properties | Array<Number> | Characteristic properties determine how the characteristic value can be used, or how the descriptor(s) can be accessed. |
| permissions | Array<Number> | The permissions of the characteristic value. |
| uuid | String | The Bluetooth-specific UUID of the characteristic. |
| descriptors | Array<Modules.BLE.Descriptor> | An array of the characteristic’s descriptors. |
create a region manager to scan beacons.
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 true if the process is initiated successfully or when the bluetooth is already off.
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 true if the process is initiated successfully or when the bluetooth is already on.
initCentralManager
since 1.0.0Initializes 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 | Type | Description |
|---|---|---|
| showPowerAlert | Boolean | A Boolean value that specifies whether the system warns the user if the app instantiates the central manager when Bluetooth service isn’t available. |
| restoreIdentifier | String | 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.0Initializes 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 | Type | Description |
|---|---|---|
| showPowerAlert | Boolean | A Boolean value that specifies whether the system warns the user if the app instantiates the peripheral manager when Bluetooth service isn’t available. |
| restoreIdentifier | String | A string containing a unique identifier (UID) for the peripheral manager to instantiate. |
Determines whether Bluetooth Low Energy Advertising feature is supported on the local Bluetooth device.
Returns true if BLE Advertising is supported on the device, false on bluetooth off or if BLE Advertising is not supported.
Determines if bluetooth permissions have been granted.
If this method returns false, then you'll need to call the
requestPermissions method to request these permissions from the user.
Returns true if bluetooth permissions have been granted
Determines if Bluetooth is currently enabled and ready for use.
Returns true if the local adapter is on.
Determines whether Bluetooth Low Energy feature is supported on the local Bluetooth device.
Returns true if BLE is supported on the device, false otherwise.
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 | Type | Description |
|---|---|---|
| callback? | Callback<Titanium.Android.RequestPermissionAccessResult> | Function to be invoked indicating if permissions were granted or not. |
Returns a Promise whose resolved value is equivalent to that passed to the optional callback argument.
Modules.BLE.Beacon
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
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.
The value identifying a group of beacons.
The value identifying a specific beacon within a group.
The relative distance to the beacon.
The received signal strength of the beacon, measured in decibels.
The time when this beacon was observed.
The unique ID of the beacons being targeted.
Modules.BLE.BeaconIdentityConstraint
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
Modules.BLE.BeaconRegion
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
This is a value that you specify and can use to identify this region inside your application.
The value identifying a group of beacons.
The value identifying a specific beacon within a group.
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.
The unique ID of the beacons being targeted.
Modules.BLE.Central
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
The address (UUID) of device acting as a central.
The maximum amount of data, in bytes, that can be received by the central in a single notification or indication.
Modules.BLE.CentralManager
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
A Boolean value that indicates whether the central is currently scanning.
All discovered peripherals
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
cancelPeripheralConnection
since 1.0.0Cancels 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 | Type | Description |
|---|---|---|
| peripheral | Modules.BLE.Peripheral | peripheral object which connnection will be canceled |
connectPeripheral
since 1.0.0Initiates 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 | Type | Description |
|---|---|---|
| peripheral | Modules.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_* |
Creates a Modules.BLE.Peripheral class object with the given address.
| Parameters | Type | Description |
|---|---|---|
| address | String | address of the remote bluetooth device. |
Determines whether the ACCESS_FINE_LOCATION permission is granted or not.
ACCESS_FINE_LOCATION permission is provided at runtime by the app user. To request this permission use requestAccessFineLocationPermission method
Returns true if the ACCESS_FINE_LOCATION permission is granted
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 | Type | Description |
|---|---|---|
| peripherals? | Array<String> | A list of peripherals UUIDs. |
| services? | Array<String> | A list of services UUIDs. |
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 the peripherals connected to the system whose services match a given set of criteria.
| Parameters | Type | Description |
|---|---|---|
| UUIDs | Array<String> | A list of service UUIDs. |
Returns a list of known peripherals by their identifiers.
| Parameters | Type | Description |
|---|---|---|
| UUIDs | Array<String> | A list of peripheral identifiers from which Peripheral objects can be retrieved. |
startScan
since 1.0.0Starts scanning for peripherals.
| Parameters | Type | Description |
|---|---|---|
| services? | Array<String> | The UUIDs of services. |
| options? | Modules.BLE.CentralScanOptions | Key/value pairs specifying options for the scan. 2 fields
|
stopScan
since 1.0.0Stops scanning for peripherals.
Events 8
This method is called upon the connection or disconnection of a peripheral that matches any of the options provided in registerForConnectionEventsWithOptions
| Event properties | Type | Description |
|---|---|---|
| event | Number | event value will be Moduels.BLE.CONNECTION_EVENT_TYPE_PEER_DISCONNECTED or Moduels.BLE.CONNECTION_EVENT_TYPE_PEER_CONNECTED |
| peripheral | Modules.BLE.Peripheral | object of peripheral. |
didConnectPeripheral
since 1.0.0This 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 | Type | Description |
|---|---|---|
| peripheral | Modules.BLE.Peripheral | An object representing the peripheral that connected to the local central manager. |
didDisconnectPeripheral
since 1.0.0This 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 | Type | Description |
|---|---|---|
| peripheral | Modules.BLE.Peripheral | An object representing the peripheral that disconnected. |
| errorCode | String | The error code; only present if an error occurred. |
| errorDomain | String | The error domain; only present if an error occurred.. |
| errorDescription | String | The error description; only peresent if an |
didDiscoverPeripheral
since 1.0.0A 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 | Type | Description |
|---|---|---|
| peripheral | Modules.BLE.Peripheral | object of discovered peripheral |
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 | Type | Description |
|---|---|---|
| peripheral | Modules.BLE.Peripheral | An object representing the peripheral that failed to connect. |
| errorCode | String | The error code; only present if an error occurred. |
| errorDomain | String | The error domain; only present if an error occurred.. |
| errorDescription | String | The error description; only peresent if an |
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 | Type | Description |
|---|---|---|
| peripheral | Modules.BLE.Peripheral | object of peripheral which disconnected. |
didUpdateState
since 1.0.0A 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 | Type | Description |
|---|---|---|
| state | Number | state of central manager |
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 | Type | Description |
|---|---|---|
| peripherals | Array<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. |
| services | Array<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. |
| options | Array<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
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.
Indicates whether this characteristic is mutable.
Whether the characteristic is currently notifying or not.
The properties of the characteristic as a bitfield.
See also CHARACTERISTIC_PROPERTY_* module constants for the possible return values of this property.
The service this characteristic belongs to.
The Bluetooth-specific UUID of the attribute.
The value of the characteristic.
Methods 1
equal
since 1.0.0tests whether two characteristics are same or not.
| Parameters | Type | Description |
|---|---|---|
| characteristic | Modules.BLE.Characteristic | the characteristic that will be compared. |
Modules.BLE.Descriptor
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
A back-pointer to the characteristic this descriptor belongs to.
The Bluetooth UUID of the descriptor.
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
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
The central that originated the request.
The descriptor whose value will be read or written.
The offset given for the value
If the remote device requires a response.
If this property is true then user need to call respondToRequest method.
The data being read or written.
Methods 1
updateValue
since 1.1.0update the data of value field
| Parameters | Type | Description |
|---|---|---|
| value | Titanium.Buffer | Titanium.Buffer object to update data on value |
Modules.BLE.L2CAPChannel
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
The peer connected to the channel
The PSM of the channel.
Methods 4
close
since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0closes the l2cap channel
getReadBufferSize
since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0Get the size of the read buffer in bytes.
Size of the read buffer in bytes.
setReadBufferSize
since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0Sets 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 | Type | Description |
|---|---|---|
| size | Number | The desired size of the read buffer in bytes. |
write
since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0write data to channel
| Parameters | Type | Description |
|---|---|---|
| data | Titanium.Buffer | Titanium.Buffer object to write data on channel |
Events 3
onDataReceived
since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0Fired whenever new data recived on channel.
| Event properties | Type | Description |
|---|---|---|
| data | Titanium.Buffer | Titanium.Buffer object which represent the read data |
Fired whenever the end of the stream has been reached.
onStreamError
since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0Fired whenever there is some error in reading or writing.
| Event properties | Type | Description |
|---|---|---|
| errorCode | String | The error code |
| errorDomain | String | The error domain |
| errorDescription | String | The error description |
Modules.BLE.MutableCharacteristic
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
The permissions of the characteristic value. It is only present if this JavaScript object represents a mutable characteristic.
For notifying characteristics, the set of currently subscribed centrals.
Modules.BLE.Peer
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
The UUID associated with the peer.
Modules.BLE.Peripheral
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
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.
A Boolean value that indicates if the remote device has authorization to receive data over ANCS protocol.
A Boolean value that indicates whether the remote device can send a write without a response.
Whether or not the peripheral is currently connected.
The name of the peripheral.
A list of a peripheral’s discovered services.
The current connection state of the peripheral. Possible values defined by PERIPHERAL_STATE_* constants.
Methods 14
discoverCharacteristics
since 1.0.0Discovers 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 | Type | Description |
|---|---|---|
| services | Modules.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. |
discoverDescriptorsForCharacteristic
since 1.0.0Discovers 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 | Type | Description |
|---|---|---|
| characteristic | Modules.BLE.Characteristic | The characteristic whose descriptors you want to discover. |
discoverIncludedServices
since 1.0.0Discovers 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 | Type | Description |
|---|---|---|
| services | Modules.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. |
discoverServices
since 1.0.0Discovers available service(s) on the peripheral. The result of this operation is returned via the didDiscoverServices event.
| Parameters | Type | Description |
|---|---|---|
| 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. |
The maximum amount of data, in bytes, you can send to a characteristic in a single write type.
| Parameters | Type | Description |
|---|---|---|
| characteristicWriteType | Number | Values representing the possible write types to a characteristic’s value. |
Attempts to open an L2CAP channel to the peripheral using the supplied Protocol/Service Multiplexer (PSM).
| Parameters | Type | Description |
|---|---|---|
| psmIdentifier | Number | 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. |
readRSSI
since 1.0.0Retrieves the current RSSI value for the peripheral while connected to the central manager.
readValueForCharacteristic
since 1.0.0Reads the value of a characteristic.The result of this operation is returned via the didUpdateValueForCharacteristic event.
| Parameters | Type | Description |
|---|---|---|
| characteristic | Modules.BLE.Characteristic | The characteristic whose value you want to read. |
readValueForDescriptor
since 1.0.0Reads the value of a descriptor. The result of this operation is returned via the didUpdateValueForDescriptor event.
| Parameters | Type | Description |
|---|---|---|
| descriptor | Modules.BLE.Descriptor | The characteristic descriptor whose value you want to read. |
Request the specific connection priority. This method will send connection parameter update request to the remote device.
| Parameters | Type | Description |
|---|---|---|
| connectionPriority | Number | Connection priority to set. Must be one of CONNECTION_PRIORITY_HIGH, CONNECTION_PRIORITY_BALANCED and CONNECTION_PRIORITY_LOW_POWER. |
subscribeToCharacteristic
since 1.0.0Enables 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 | Type | Description |
|---|---|---|
| characteristic | Modules.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. |
unsubscribeFromCharacteristic
since 1.0.0Disables notifications/indications for a characteristic.
| Parameters | Type | Description |
|---|---|---|
| characteristic | Modules.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. |
writeValueForCharacteristic
since 1.0.0Writes a value to a characteristic.
| Parameters | Type | Description |
|---|---|---|
| characteristic | Modules.BLE.Characteristic | The characteristic whose value you want to write. |
| data | Titanium.Buffer | The new value of the characteristic. |
| characteristicWriteType | Number | The type of write to be executed. See CHARACTERISTIC_TYPE_WRITE_WITH_RESPONSE and CHARACTERISTIC_TYPE_WRITE_WITHOUT_RESPONSE. |
writeValueForDescriptor
since 1.0.0Writes 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 | Type | Description |
|---|---|---|
| descriptor | Modules.BLE.Descriptor | The descriptor whose value you want to write. |
| data | Titanium.Buffer | The new value of the characteristic. |
Events 14
didDiscoverCharacteristics
since 1.0.0This 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 | Type | Description |
|---|---|---|
| sourcePeripheral | Modules.BLE.Peripheral | The peripheral providing this information. |
| service | Modules.BLE.Service | The service to which the characteristics belong. |
| errorCode | String | The error code; only present if an error occurred. |
| errorDomain | String | The error domain; only present if an error occurred. |
| errorDescription | String | The error description; only peresent if an error occurred. |
didDiscoverDescriptorsForCharacteristics
since 1.0.0This 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 | Type | Description |
|---|---|---|
| sourcePeripheral | Modules.BLE.Peripheral | The peripheral providing this information. |
| characteristic | Modules.BLE.Characteristic | The service to which the characteristics belong. |
| errorCode | String | The error code; only present if an error occurred. |
| errorDomain | String | The error domain; only present if an error occurred. |
| errorDescription | String | The error description; only peresent if an error occurred. |
didDiscoverIncludedServices
since 1.0.0This 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 | Type | Description |
|---|---|---|
| sourcePeripheral | Modules.BLE.Peripheral | The peripheral providing this information. |
| errorCode | String | The error code; only present if an error occurred. |
| errorDomain | String | The error domain; only present if an error occurred. |
| errorDescription | String | The error description; only peresent if an error occurred. |
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 | Type | Description |
|---|---|---|
| sourcePeripheral | Modules.BLE.Peripheral | The peripheral providing this information. |
| errorCode | String | The error code; only present if an error occurred. |
| errorDomain | String | The error domain; only present if an error occurred. |
| errorDescription | String | The error description; only peresent if an error occurred. |
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 | Type | Description |
|---|---|---|
| sourcePeripheral | Modules.BLE.Peripheral | The peripheral providing this information. |
| services | Array<Modules.BLE.Service> | The services that have been invalidated. |
didOpenChannel
since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0This method delivers the result of a previous call to openL2CAPChannel.
Delivers the result of an attempt to open an L2CAP channel.
| Event properties | Type | Description |
|---|---|---|
| sourcePeripheral | Modules.BLE.Peripheral | The peripheral sending the event. |
| channel | Modules.BLE.L2CAPChannel | A live L2CAP connection to a remote device. |
| errorCode | String | The error code; only present if an error occurred. |
| errorDomain | String | The error domain; only present if an error occurred. |
| errorDescription | String | The error description; only peresent if an error occurred. |
didReadRSSI
since 1.0.0This 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 | Type | Description |
|---|---|---|
| sourcePeripheral | Modules.BLE.Peripheral | The peripheral providing this information. |
| rssi | Number | value last read |
| errorCode | String | The error code; only present if an error occurred. |
| errorDomain | String | The error domain; only present if an error occurred. |
| errorDescription | String | The error description; only peresent if an error occurred. |
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 | Type | Description |
|---|---|---|
| sourcePeripheral | Modules.BLE.Peripheral | The peripheral providing this information. |
didUpdateNotificationStateForCharacteristics
since 1.0.0This 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 | Type | Description |
|---|---|---|
| sourcePeripheral | Modules.BLE.Peripheral | The peripheral providing this information. |
| characteristic | Modules.BLE.Characteristic | The characteristic to subscribe. |
| isSubscribed | Boolean | A Boolean value that specifies whether the didUpdateNotificationStateForCharacteristics event is for subscribe or unsubscribe operation. true, if subscribe and false otherwise. |
| errorCode | String | The error code; only present if an error occurred. |
| errorDomain | String | The error domain; only present if an error occurred. |
| errorDescription | String | The error description; only peresent if an error occurred. |
didUpdateValueForCharacteristic
since 1.0.0This 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 | Type | Description |
|---|---|---|
| sourcePeripheral | Modules.BLE.Peripheral | The peripheral providing this information. |
| characteristic | Modules.BLE.Characteristic | The characteristic containing the value. |
| errorCode | String | The error code; only present if an error occurred. |
| errorDomain | String | The error domain; only present if an error occurred. |
| errorDescription | String | The error description; only peresent if an error occurred. |
didUpdateValueForDescriptor
since 1.0.0This 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 | Type | Description |
|---|---|---|
| sourcePeripheral | Modules.BLE.Peripheral | The peripheral providing this information. |
| descriptor | Modules.BLE.Descriptor | The characteristic descriptor containing the value. |
| errorCode | String | The error code; only present if an error occurred. |
| errorDomain | String | The error domain; only present if an error occurred. |
| errorDescription | String | The error description; only peresent if an error occurred. |
didWriteValueForCharacteristic
since 1.0.0This 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 | Type | Description |
|---|---|---|
| sourcePeripheral | Modules.BLE.Peripheral | The peripheral providing this information. |
| characteristic | Modules.BLE.Characteristic | The characteristic containing the value. |
| errorCode | String | The error code; only present if an error occurred. |
| errorDomain | String | The error domain; only present if an error occurred. |
| errorDescription | String | The error description; only peresent if an error occurred. |
didWriteValueForDescriptor
since 1.0.0This 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 | Type | Description |
|---|---|---|
| sourcePeripheral | Modules.BLE.Peripheral | The peripheral sending the event. |
| descriptor | Modules.BLE.Descriptor | The object representing the descriptor that was changed. |
| errorCode | String | The error code; only present if an error occurred. |
| errorDomain | String | The error domain; only present if an error occurred. |
| errorDescription | String | 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 | Type | Description |
|---|---|---|
| sourcePeripheral | Modules.BLE.Peripheral | The peripheral sending the event. |
Modules.BLE.PeripheralManager
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
Whether or not the the module's internal peripheral manager is currently advertising data.
State of the module's internal peripheral manager. Its value is one of the MANAGER_STATE_* constants.
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.0Publishes a service and any of its associated characteristics and characteristic descriptors to the local GATT database.
| Parameters | Type | Description |
|---|---|---|
| characteristics | Array<Modules.BLE.Characteristic> | A list of characteristics of a service. |
| uuid | String | The Bluetooth-specific UUID of the attribute. |
| primary | Boolean | The type of the service (primary or secondary). |
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.
Attempts to open an L2CAP channel to the peripheral using the supplied Protocol/Service Multiplexer (PSM).
| Parameters | Type | Description |
|---|---|---|
| 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. |
removeAllServices
since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0Removes all published services from the local GATT database.
removeService
since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0Removes a specified published service from the local GATT database.
| Parameters | Type | Description |
|---|---|---|
| service | Modules.BLE.Service | Object of service you want to remove. |
Used to respond to request(s) received via the didReceiveDescriptorReadRequest or didReceiveDescriptorWriteRequest event.
| Parameters | Type | Description |
|---|---|---|
| descriptorRequest | Modules.BLE.DescriptorRequest | The request to which the peripheral is responding. |
| result | Number | The result code; see the ATT_ERROR* constants. |
respondToRequest
since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0Used to respond to request(s) received via the didReceiveReadRequest or didReceiveWriteRequests event.
| Parameters | Type | Description |
|---|---|---|
| request | Modules.BLE.Request | The request to which the peripheral is responding. |
| result | Number | The result code; see the ATT_ERROR* constants. |
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 | Type | Description |
|---|---|---|
| latency | Number | The desired connection latency. see BLE.PERIPHERAL_MANAGER_CONNECTION_LATENCY_* |
| central | Modules.BLE.Central | A connected central |
startAdvertising
since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0Instructs 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 | Type | Description |
|---|---|---|
| localName | String | Boolean | The local name of a peripheral. This parameter is of type boolean in android |
| serviceUUIDs | Array<String> | An array of service UUIDs. |
Instructs the module's internal peripheral manager to start advertising for beacon region.
Important: You must call the initPeripheralManager function first!
| Parameters | Type | Description |
|---|---|---|
| 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. |
| beaconRegion | Modules.BLE.BeaconRegion | Object of Beacon Region. |
stopAdvertising
since 1.0.0Instructs the module's internal peripheral manager to stop advertising.
The service PSM to be removed from the system.
| Parameters | Type | Description |
|---|---|---|
| PSM | Number | The PSM of the channel along with we can close the particular channel. |
updateValue
since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0Instructs the module's internal peripheral manager to send an updated characteristic value to one or more centrals, via a notification or indication.
| Parameters | Type | Description |
|---|---|---|
| characteristic | Modules.BLE.MutableCharacteristic | The value of the characteristic. |
| data | Titanium.Buffer | updated characteristic value. |
| centrals | Array<Modules.BLE.Central> | The list of centrals that need to be updated. If not specified, all subscribed centrals will be updated. |
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.0This 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 | Type | Description |
|---|---|---|
| service | Modules.BLE.Service | An object representing the service that was added. |
| errorCode | String | The error code; only present if an error occurred. |
| errorDomain | String | The error domain; only present if an error occurred.. |
| errorDescription | String | The error description; only peresent if an |
didOpenL2CAPChannel
since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0Tells the delegate that the peripheral manager opened an L2CAP channel.
| Event properties | Type | Description |
|---|---|---|
| channel | Modules.BLE.L2CAPChannel | The channel opened by the manager. |
| errorCode | String | The error code; only present if an error occurred. |
| errorDomain | String | The error domain; only present if an error occurred.. |
| errorDescription | String | The error description; only peresent if an |
didPublishL2CAPChannel
since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0Tells the delegate that the peripheral manager created a listener for incoming L2CAP channel connections.
| Event properties | Type | Description |
|---|---|---|
| psm | Number | The Protocol/Service Multiplexer (PSM) of the published channel. |
| errorCode | String | The error code; only present if an error occurred. |
| errorDomain | String | The error domain; only present if an error occurred.. |
| errorDescription | String | The error description; only peresent if an |
This event is fired when the module's internal peripheral manager receives a read request on descriptor.
| Event properties | Type | Description |
|---|---|---|
| descriptorRequest | Modules.BLE.DescriptorRequest | An object representing the descriptor request. |
This event is fired when the module's internal peripheral manager receives a write request on descriptor.
| Event properties | Type | Description |
|---|---|---|
| descriptorRequests | Modules.BLE.DescriptorRequest | An object representing the descriptor request. |
didReceiveReadRequest
since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0This event is fired when the module's internal peripheral manager receives a read request.
| Event properties | Type | Description |
|---|---|---|
| request | Modules.BLE.Request | An object representing the request. |
didReceiveWriteRequests
since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0This 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 | Type | Description |
|---|---|---|
| request | Array<Modules.BLE.Request> | request objects describing the incoming write request |
didStartAdvertising
since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0This 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 | Type | Description |
|---|---|---|
| errorCode | String | The error code; only present if an error occurred. |
| errorDomain | String | The error domain; only present if an error occurred.. |
| errorDescription | String | The error description; only peresent if an |
didSubscribeToCharacteristic
since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0This 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 | Type | Description |
|---|---|---|
| central | Modules.BLE.Central | An object representing the central that subscribed. |
| characteristic | Modules.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.0Tells the delegate that the peripheral manager removed a published service from the local system.
| Event properties | Type | Description |
|---|---|---|
| psm | Number | The Protocol/Service Multiplexer (PSM) of the published channel. |
| errorCode | String | The error code; only present if an error occurred. |
| errorDomain | String | The error domain; only present if an error occurred.. |
| errorDescription | String | The error description; only peresent if an |
didUnsubscribeFromCharacteristic
since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0This 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 | Type | Description |
|---|---|---|
| central | Modules.BLE.Central | An object representing the central that unsubscribed. |
| characteristic | Modules.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.0Fired whenever the state of the module's internal peripheral manager changes.
| Event properties | Type | Description |
|---|---|---|
| state | Number | An integer describing the state of the module's internal peripheral manager. See the MANAGER_STATE_* constants. |
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.
Tells the delegate that the peripheral manager opened an L2CAP channel.
| Event properties | Type | Description |
|---|---|---|
| advertisementData | Object | 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. |
| services | Array<String> | Array of uuids of Services |
Modules.BLE.RegionManager
Extends Titanium.Proxy
An object that manages and scan beacons.
Properties 8
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.
Determines whether the device supports ranging.
If false, all attempts to range beacons will fail.
Returns the current authorization status of the calling application.
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.
Retrieve a set of beacon constraints for which this location manager is actively providing ranging.
Retrieve a set of objects representing the regions for which this location manager is actively providing ranging.
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
Asynchronously retrieve the cached state of the specified region. The state is returned to the "didDetermineState" event
| Parameters | Type | Description |
|---|---|---|
| beaconRegion | Modules.BLE.BeaconRegion | Beacon region which state is requested |
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>
Start calculating ranges for beacons in the specified region.
| Parameters | Type | Description |
|---|---|---|
| beaconRegion | Modules.BLE.BeaconRegion | Beacon region object |
Start calculating ranges for beacons in the specified region.
| Parameters | Type | Description |
|---|---|---|
| identityConstraint | Modules.BLE.BeaconIdentityConstraint | Beacon identity constraint object |
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 | Type | Description |
|---|---|---|
| beaconRegion | Modules.BLE.BeaconRegion | Beacon region object |
Stop calculating ranges for the specified region.
| Parameters | Type | Description |
|---|---|---|
| beaconRegion | Modules.BLE.BeaconRegion | Beacon region object |
Stop an earlier beacon ranging request. See startRangingBeaconsSatisfyingIdentityConstraint:.
| Parameters | Type | Description |
|---|---|---|
| identityConstraint | Modules.BLE.BeaconIdentityConstraint | Beacon identity constraint object |
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 | Type | Description |
|---|---|---|
| beaconRegion | Modules.BLE.BeaconRegion | Beacon region object |
Events 11
didChangeAuthorization
iOS 14.0+Invoked when the authorization status changes for this application.
| Event properties | Type | Description |
|---|---|---|
| state | Number | 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 | Type | Description |
|---|---|---|
| region | Modules.BLE.BeaconRegion | Beacon region object |
| state | Number | current state value. see REGION_STATE_* for possible values |
Invoked when the user enters a monitored region.
| Event properties | Type | Description |
|---|---|---|
| region | Modules.BLE.BeaconRegion | Beacon region object |
Invoked when the user exits a monitored region
| Event properties | Type | Description |
|---|---|---|
| region | Modules.BLE.BeaconRegion | Beacon region object |
Invoked when an any error has occurred.
| Event properties | Type | Description |
|---|---|---|
| errorCode | String | The error code; only present if an error occurred. |
| errorDomain | String | The error domain; only present if an error occurred.. |
| errorDescription | String | The error description; only peresent if any |
didFailRanging
iOS 13.0+Invoked when an error has occurred ranging beacons in a region.
| Event properties | Type | Description |
|---|---|---|
| beaconConstraint | Modules.BLE.BeaconIdentityConstraint | Beacon Identity Constraint object |
| errorCode | String | The error code; only present if an error occurred. |
| errorDomain | String | The error domain; only present if an error occurred.. |
| errorDescription | String | 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 | Type | Description |
|---|---|---|
| beaconConstraint | Modules.BLE.BeaconIdentityConstraint | Beacon Identity Constraint object |
| beacons | Array<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 | Type | Description |
|---|---|---|
| region | Modules.BLE.BeaconRegion | Beacon region object |
| beacons | Array<Modules.BLE.Beacon> | Beacon objects |
Invoked when a monitoring for a region started successfully.
| Event properties | Type | Description |
|---|---|---|
| region | Modules.BLE.BeaconRegion | Beacon region object |
Invoked when an error has occurred monitoring beacons in a region.
| Event properties | Type | Description |
|---|---|---|
| region | Modules.BLE.BeaconRegion | Beacon region object |
| errorCode | String | The error code; only present if an error occurred. |
| errorDomain | String | The error domain; only present if an error occurred.. |
| errorDescription | String | The error description; only peresent if any |
Invoked when an error has occurred ranging beacons in a region.
| Event properties | Type | Description |
|---|---|---|
| region | Modules.BLE.BeaconRegion | Beacon region object |
| errorCode | String | The error code; only present if an error occurred. |
| errorDomain | String | The error domain; only present if an error occurred.. |
| errorDescription | String | The error description; only peresent if any |
Modules.BLE.Request
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
The central that originated the request.
The characteristic whose value will be read or written.
The zero-based index of the first byte for the read or write.
If the remote device requires a response.
If this property is true then user need to call respondToRequest method.
The data being read or written.
Methods 1
updateValue
since Android 1.1.0, iPhone 1.0.0, iPad 1.0.0update the data of value field
| Parameters | Type | Description |
|---|---|---|
| value | Titanium.Buffer | Titanium.Buffer object to update data on value |
Modules.BLE.Service
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
A list of characteristics discovered in this service.
A list of included services discovered in this service.
A Boolean value that indicates whether the type of service is primary or secondary.
The peripheral to which this service belongs.
The Bluetooth-specific UUID of the attribute.