Skip to content

Modules.BLE.CentralManager

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.

Extends: Titanium.Proxy · Since: 1.0.0 · Platforms: android, iphone, ipad

Properties #

isScanning#

Type: Boolean

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

peripherals#

Type: Array<Modules.BLE.Peripheral>

All discovered peripherals

state#

Type: Number

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 #

cancelPeripheralConnection #

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:
NameTypeSummaryOptional
peripheralModules.BLE.Peripheralperipheral object which connnection will be canceledNo

Returns: void

connectPeripheral #

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:
NameTypeSummaryOptional
peripheralModules.BLE.Peripheralperipheral object to connectNo
optionsObjectThis 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_*Yes

Returns: void

createPeripheral #

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

Parameters:
NameTypeSummaryOptional
addressStringaddress of the remote bluetooth device.No

Returns: Modules.BLE.Peripheral

isAccessFineLocationPermissionGranted #

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: Boolean — Returns true if the ACCESS_FINE_LOCATION permission is granted

registerForConnectionEvents #

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:
NameTypeSummaryOptional
peripheralsArray<String>A list of peripherals UUIDs.Yes
servicesArray<String>A list of services UUIDs.Yes

Returns: void

requestAccessFineLocationPermission #

Request for the ACCESS_FINE_LOCATION.

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

retrieveConnectedPeripheralsWithServices #

Returns a list of the peripherals connected to the system whose services match a given set of criteria.

Parameters:
NameTypeSummaryOptional
UUIDsArray<String>A list of service UUIDs.No

Returns: Array<Modules.BLE.Peripheral>

retrievePeripheralsWithIdentifiers #

Returns a list of known peripherals by their identifiers.

Parameters:
NameTypeSummaryOptional
UUIDsArray<String>A list of peripheral identifiers from which Peripheral objects can be retrieved.No

Returns: Array<Modules.BLE.Peripheral>

startScan #

Starts scanning for peripherals.

Parameters:
NameTypeSummaryOptional
servicesArray<String>The UUIDs of services.Yes
optionsModules.BLE.CentralScanOptionsKey/value pairs specifying options for the scan.Yes

Returns: void

stopScan #

Stops scanning for peripherals.

Returns: void

Events #

connectionEventDidOccur #

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

Event Properties:
NameTypeSummary
eventNumberevent value will be Moduels.BLE.CONNECTION_EVENT_TYPE_PEER_DISCONNECTED or Moduels.BLE.CONNECTION_EVENT_TYPE_PEER_CONNECTED
peripheralModules.BLE.Peripheralobject of peripheral.

didConnectPeripheral #

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:
NameTypeSummary
peripheralModules.BLE.PeripheralAn object representing the peripheral that connected to the local central manager.

didDisconnectPeripheral #

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:
NameTypeSummary
peripheralModules.BLE.PeripheralAn object representing the peripheral that disconnected.
errorCodeStringThe error code; only present if an error occurred.
errorDomainStringThe error domain; only present if an error occurred..
errorDescriptionStringThe error description; only peresent if an

didDiscoverPeripheral #

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:
NameTypeSummary
peripheralModules.BLE.Peripheralobject of discovered peripheral

didFailToConnectPeripheral #

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:
NameTypeSummary
peripheralModules.BLE.PeripheralAn object representing the peripheral that failed to connect.
errorCodeStringThe error code; only present if an error occurred.
errorDomainStringThe error domain; only present if an error occurred..
errorDescriptionStringThe error description; only peresent if an

didUpdateANCSAuthorization #

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:
NameTypeSummary
peripheralModules.BLE.Peripheralobject of peripheral which disconnected.

didUpdateState #

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:
NameTypeSummary
stateNumberstate of central manager

willRestoreState #

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:
NameTypeSummary
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.

Titanium SDK Documentation