UHNBLEController Class Reference

Inherits from NSObject
Declared in UHNBLEController.h

Overview

The UHNBLEController provides a simplified interface to Core Bluetooth (CB) by handling fault checking and removing ann CB specific details. Through the inteface and delegate protocol, one should be able to easily make requests of a BLE peripheral device.

Properties

  notifyOnConnection

Indicates if the OS should notify the user when a peripheral is connected

@property (nonatomic, assign) BOOL notifyOnConnection

Declared In

UHNBLEController.h

  notifyOnDisconnection

Indicates if the OS should notify the user when a peripheral is disconnected

@property (nonatomic, assign) BOOL notifyOnDisconnection

Declared In

UHNBLEController.h

  notifyOnNotification

Indicates if the OS should notify the user when the peripheral has issued a notification or indication

@property (nonatomic, assign) BOOL notifyOnNotification

Declared In

UHNBLEController.h

  storeLastConnectedDeviceID

Indicates if the last connected device should be stored for a future reconnection

@property (nonatomic, assign) BOOL storeLastConnectedDeviceID

Declared In

UHNBLEController.h

Initializing a UHNBLEController

– initWithDelegate:requiredServices:

UHNBLEController is initialized with a delegate and optional required services.

- (instancetype)initWithDelegate:(id<UHNBLEControllerDelegate>)delegate requiredServices:(NSArray *)services

Parameters

delegate

The delegate object that will received discovery, connectivity, and read/write events. This parameter is mandatory.

services

The required services used to filter eligibility of discovered peripherals. Only peripherals that advertist all the required services will be deemed eligible and reported to the delegate. If services is nil, all peripherals discovered will be reported to the delegate.

Return Value

Instance of a UHNBLEController

Declared In

UHNBLEController.h

Connection Methods

– startConnection

Starts the connection process. If a peripheral was previously connected, it will try to reconnect to that peripheral. Otherwise, it starts a scan.

- (void)startConnection

Discussion

automatically called when bluetooth is powered on

Declared In

UHNBLEController.h

– connectToDiscoveredPeripheral:

Try to connect to a peripheral that was already discovered.

- (void)connectToDiscoveredPeripheral:(NSString *)deviceName

Parameters

deviceName

The name of device which has been previously discovered and with which the delegate would like to connect

Discussion

When a peripheral is discovered, the delegate received a discovered peripheral event. connectToDiscoveredDevice should not be used to unless the delegate has already received a discovered peripheral event.

If this method makes a successful connection, the delegate could receive the [UHNBLEControllerDelegate bleController:didConnectWithPeripheral:withUUID:] event and the discovery of the provided required services during initiation is initiated. Once the required services have been discovered, the delegate could recieve the [UHNBLEControllerDelegate bleController:didConnectWithPeripheral:withServices:andUUID:] event and the discovery of all characteristics available for each of the required services is initiated. Once all the characeristics for all the required services have been discovered, the delegate could receive the [UHNBLEControllerDelegate bleController:didDiscoverCharacteristics:forService:] event. If required services are provided with instantiation of the UHNBLEController, it is suggested to start making requests with the connected peripheral after the [UHNBLEControllerDelegate bleController:didDiscoverCharacteristics:forService:] event is received.

If no required services were provided, it is up to the delegate to discover the services, using discoverServices: and characteristics, using either discoverAllCharacteristicsForService: or discoverCharacteristics:forService: before making requests of the peripheral.

Declared In

UHNBLEController.h

– reconnectToPeripheralWithUUID:

Try to reconnect with a peripheral that was previously connected

- (void)reconnectToPeripheralWithUUID:(NSUUID *)uuid

Parameters

uuid

The NSUUID of the peripheral that was perviously connected

Declared In

UHNBLEController.h

– cancelConnection

Cancel the existing connecttion.

- (void)cancelConnection

Declared In

UHNBLEController.h

– isPeripheralConnected

Determine if a peripheral is connected

- (BOOL)isPeripheralConnected

Return Value

YES if a peripheral is connected, otherwise NO

Declared In

UHNBLEController.h

Discover Methods

– discoverServices:

Discover services of interest with the connected peripheral.

- (void)discoverServices:(NSArray *)serviceUUIDs

Parameters

serviceUUIDs

An array of NSString representing the UUIDs of the interested services.

Discussion

If this method is successful, the delegate could get the optional [UHNBLEControllerDelegate bleController:didDiscoverServices:] event including all the discovered service UUIDs

Warning: If no requried services were provided during initiation, the delegate must use discoverServices: before making requests of the peripheral. Also, if the delegate would like to make use of an other availabe service, it must first be discovered.

Declared In

UHNBLEController.h

– discoverAllCharacteristicsForService:

Discover all characteristics for the provided service

- (void)discoverAllCharacteristicsForService:(NSString *)serviceUUID

Parameters

serviceUUID

A NSString representing the UUID of the service of interest

Discussion

The service must have been discovered before the characteristics of the service can be discovered.

If this method is successful, the delegate could get the optional [UHNBLEControllerDelegate bleController:didDiscoverCharacteristics:forService:] event including all the discovered characteristic UUIDs

Warning: If no requried services were provided during initiation, the delegate must use either discoverAllCharacteristicsForService: or discoverCharacteristics:forService: before making requests of the peripheral.

Declared In

UHNBLEController.h

– discoverCharacteristics:forService:

Discover speicific characteristics for the provided service

- (void)discoverCharacteristics:(NSArray *)characteristicUUIDs forService:(NSString *)serviceUUID

Parameters

characteristicUUIDs

An array of NSString representing the characteristics of interest.

serviceUUID

A NSString representing the service for which the characteristics should be available

Discussion

The service must have been discovered before the characteristics of the service can be discovered.

If this method is successful, the delegate could get the optional [UHNBLEControllerDelegate bleController:didDiscoverCharacteristics:forService:] event including all the discovered characteristic UUIDs.

If the service is not available, the delegate could get the optional [UHNBLEControllerDelegate bleController:serviceNotAvailable:] event.

Warning: If no requried services were provided during initiation, the delegate must use either discoverAllCharacteristicsForService: or discoverCharacteristics:forService: before making requests of the peripheral.

Declared In

UHNBLEController.h

– isServiceAvailable:

Determine is a service is available in the connected peripheral

- (BOOL)isServiceAvailable:(NSString *)serviceUUID

Parameters

serviceUUID

A NSString representing the UUID of the service of interest

Return Value

YES if the service is available in the connected peripheral, otherwise NO

Declared In

UHNBLEController.h

Read & Write Methods

– writeValue:toCharacteristicUUID:withServiceUUID:

Try to write data to a characteristic

- (void)writeValue:(NSData *)data toCharacteristicUUID:(NSString *)characteristicUUID withServiceUUID:(NSString *)serviceUUID

Parameters

data

The value to write to the characteristic

characteristicUUID

A NSString representing the UUID of the characteristic

serviceUUID

A NSString representing the UUID of the service

Discussion

If this method is successful, the delegate will receive a [UHNBLEControllerDelegate bleController:didWriteValue:toCharacteristic:] event. If the method is unsuccessful, the delegate could receive the [UHNBLEControllerDelegate bleController:failedWriteToCharacteristic:].

If the service is not available, the delegate could get the optional [UHNBLEControllerDelegate bleController:serviceNotAvailable:] event.

If the character is not available, the delegate could get the optional [UHNBLEControllerDelegate bleController:characteristicNotAvailable:] event.

Declared In

UHNBLEController.h

– readValueFromCharacteristicUUID:withServiceUUID:

Try to read the value of a characteristic

- (void)readValueFromCharacteristicUUID:(NSString *)characteristicUUID withServiceUUID:(NSString *)serviceUUID

Parameters

characteristicUUID

A NSString representing the UUID of the characteristic

serviceUUID

A NSString representing the UUID of the service

Discussion

Writes to a characteristic are indicated, meaning that a response is provided from the peripheral once the write was successful. If this method is successful, the delegate will receive a [UHNBLEControllerDelegate bleController:didUpdateValue:forCharacteristic:] event. If the method is unsuccessful, the delegate could receive the [UHNBLEControllerDelegate bleController:failedReadOfCharacteristic:].

If the service is not available, the delegate could get the optional [UHNBLEControllerDelegate bleController:serviceNotAvailable:] event.

If the character is not available, the delegate could get the optional a [UHNBLEControllerDelegate bleController:characteristicNotAvailable:] event.

Declared In

UHNBLEController.h

– setNotificationState:forCharacteristicUUID:withServiceUUID:

Try to set a notification or indication state of a characteristic

- (void)setNotificationState:(BOOL)notify forCharacteristicUUID:(NSString *)characteristicUUID withServiceUUID:(NSString *)serviceUUID

Parameters

notify

Indicates whether notifications or indications should be enabled or disabled

characteristicUUID

A NSString representing the UUID of the characteristic

serviceUUID

A NSString representing the UUID of the service

Discussion

If this method is successful, the delegate will receive a [UHNBLEControllerDelegate bleController:didUpdateValue:forCharacteristic:] event. If the method is unsuccessful, the delegate could receive the [UHNBLEControllerDelegate bleController:failedNotificationUpdateToCharacteristic:].

If the service is not available, the delegate could get the optional [UHNBLEControllerDelegate bleController:serviceNotAvailable:] event.

If the character is not available, the delegate could get the optional a [UHNBLEControllerDelegate bleController:characteristicNotAvailable:] event.

Declared In

UHNBLEController.h