YMSCBPeripheral Class Reference

Inherits from NSObject
Conforms to CBPeripheralDelegate
Declared in YMSCBPeripheral.h
YMSCBPeripheral.m

Overview

Base class for defining a Bluetooth LE peripheral.

YMSCBPeripheral holds an instance of CBPeripheral (cbPeripheral) and implements the CBPeripheralDelegate messages sent by cbPeripheral.

The BLE services discovered by cbPeripheral are encapulated in instances of YMSCBService and contained in the dictionary serviceDict.

Properties

  base

128 bit address base

@property (nonatomic, assign) yms_u128_t base

Discussion

128 bit address base

Declared In

YMSCBPeripheral.h

  name

Convenience accessor for cbPeripheral.name.

@property (nonatomic, readonly) NSString *name

Discussion

Convenience accessor for cbPeripheral.name.

Declared In

YMSCBPeripheral.h

  delegate

Pointer to delegate.

@property (nonatomic, weak) id<CBPeripheralDelegate> delegate

Discussion

Pointer to delegate.

The delegate object will be forwarded CBPeripheralDelegate messages sent by cbPeripheral.

Declared In

YMSCBPeripheral.h

  watchdogRaised

Flag to indicate if the watchdog timer has expired and forced a disconnect.

@property (nonatomic, assign) BOOL watchdogRaised

Discussion

Flag to indicate if the watchdog timer has expired and forced a disconnect.

Declared In

YMSCBPeripheral.h

  serviceDict

Dictionary of (key, value) pairs of (NSString, YMSCBService) instances.

@property (nonatomic, strong) NSDictionary *serviceDict

Discussion

Dictionary of (key, value) pairs of (NSString, YMSCBService) instances.

The NSString key is typically a “human-readable” string to easily reference a YMSCBService.

Declared In

YMSCBPeripheral.h

  cbPeripheral

The CBPeripheral instance.

@property (nonatomic, strong) CBPeripheral *cbPeripheral

Discussion

The CBPeripheral instance.

Declared In

YMSCBPeripheral.h

  isConnected

A Boolean value indicating whether the peripheral is currently connected to the central manager. (read-only)

@property (readonly) BOOL isConnected

Discussion

A Boolean value indicating whether the peripheral is currently connected to the central manager. (read-only)

This value is populated with cbPeripheral.isConnected.

Declared In

YMSCBPeripheral.h

  rssiPingPeriod

Time period between RSSI pings. (Default: 2 seconds)

@property (nonatomic, assign) NSTimeInterval rssiPingPeriod

Discussion

Time period between RSSI pings. (Default: 2 seconds)

This is a convenience property to hold a ping period for RSSI updates. No policy or mechanism for invoking readRSSI is provided for by YMSCBPeripheral or YMSCoreBluetooth.

Declared In

YMSCBPeripheral.h

  central

Pointer to an instance of YMSCBCentralManager.

@property (nonatomic, weak) YMSCBCentralManager *central

Discussion

Pointer to an instance of YMSCBCentralManager.

Declared In

YMSCBPeripheral.h

  watchdogTimer

Watchdog timer for connection.

@property (nonatomic, strong) NSTimer *watchdogTimer

Discussion

Watchdog timer for connection.

Declared In

YMSCBPeripheral.h

  watchdogTimerInterval

Watchdog timer interval in seconds. Default is 5 seconds.

@property (nonatomic, assign) NSTimeInterval watchdogTimerInterval

Discussion

Watchdog timer interval in seconds. Default is 5 seconds.

Declared In

YMSCBPeripheral.h

  connectCallback

Holds callback for connection established.

@property (nonatomic, copy) YMSCBPeripheralConnectCallbackBlockType connectCallback

Discussion

Holds callback for connection established.

Declared In

YMSCBPeripheral.h

  discoverServicesCallback

Holds callback for services discovered.

@property (nonatomic, copy) YMSCBPeripheralDiscoverServicesBlockType discoverServicesCallback

Discussion

Holds callback for services discovered.

Declared In

YMSCBPeripheral.h

  isRenderedInViewCell

Helper flag to determine ViewCell updates.

@property (nonatomic, assign) BOOL isRenderedInViewCell

Discussion

Helper flag to determine ViewCell updates.

Declared In

YMSCBPeripheral.h

Initializing a YMSCBPeripheral

– initWithPeripheral:central:baseHi:baseLo:

Constructor.

- (instancetype)initWithPeripheral:(CBPeripheral *)peripheral central:(YMSCBCentralManager *)owner baseHi:(int64_t)hi baseLo:(int64_t)lo

Parameters

peripheral

Pointer to CBPeripheral

owner

Pointer to YMSCBCentralManager

hi

Top 64 bits of 128-bit base address value

lo

Bottom 64 bits of 128-bit base address value

Return Value

instance of this class

Discussion

Constructor.

This method must be called via super in any subclass implementation.

The implementation of this method in a subclass will populate serviceDict with (key, value) pairs of (NSString, YMSCBService) instances, where key is typically a “human-readable” string to easily reference a YMSCBService.

Declared In

YMSCBPeripheral.h

Get all CBService CBUUIDs for this peripheral

– services

Generate array of CBUUID for all CoreBluetooth services associated with this peripheral.

- (NSArray *)services

Return Value

array of CBUUID services

Discussion

Generate array of CBUUID for all CoreBluetooth services associated with this peripheral.

The output of this method is to be passed to the method discoverServices: in CBPeripheral:

Declared In

YMSCBPeripheral.h

– servicesSubset:

Return array of CBUUIDs for YMSCBService instances in serviceDict whose key is included in keys.

- (NSArray *)servicesSubset:(NSArray *)keys

Parameters

keys

array of NSString keys, where each key must exist in serviceDict

Return Value

array of CBUUIDs

Discussion

Return array of CBUUIDs for YMSCBService instances in serviceDict whose key is included in keys.

Declared In

YMSCBPeripheral.h

Find a YMSCBService

– findService:

Find YMSCBService given its corresponding CBService.

- (YMSCBService *)findService:(CBService *)service

Parameters

service

CBService to search for in serviceDict.

Return Value

YMSCBService instance which holds service.

Discussion

Find YMSCBService given its corresponding CBService.

Declared In

YMSCBPeripheral.h

– connect

Connect peripheral

- (void)connect

Discussion

Connect peripheral

Declared In

YMSCBPeripheral.h

– disconnect

Disconnect peripheral

- (void)disconnect

Discussion

Disconnect peripheral

Declared In

YMSCBPeripheral.h

– readRSSI

Invokes CBPeripheral.readRSSI method to retrieve current RSSI value for cbPeripheral.

- (void)readRSSI

Discussion

Invokes CBPeripheral.readRSSI method to retrieve current RSSI value for cbPeripheral.

Declared In

YMSCBPeripheral.h

– resetWatchdog

Initialize or reset watchdog timer.

- (void)resetWatchdog

Discussion

Initialize or reset watchdog timer.

Declared In

YMSCBPeripheral.h

– invalidateWatchdog

Invalidate watchdog timer.

- (void)invalidateWatchdog

Discussion

Invalidate watchdog timer.

Declared In

YMSCBPeripheral.h

– watchdogDisconnect

Disconnect if watchdog times out.

- (void)watchdogDisconnect

Discussion

Disconnect if watchdog times out.

Declared In

YMSCBPeripheral.h

– connectWithOptions:withBlock:

Establishes connection to peripheral with callback block.

- (void)connectWithOptions:(NSDictionary *)options withBlock:(void ( ^ ) ( YMSCBPeripheral *yp , NSError *error ))connectCallback

Parameters

options

A dictionary to customize the behavior of the connection. See “Peripheral Connection Options” for CBCentralManager.

connectCallback

Callback block to handle peripheral connection.

Discussion

Establishes connection to peripheral with callback block.

Declared In

YMSCBPeripheral.h

– cancelConnection

Cancels an active or pending local connection to a peripheral.

- (void)cancelConnection

Discussion

Cancels an active or pending local connection to a peripheral.

Declared In

YMSCBPeripheral.h

– handleConnectionResponse:

Executes connect callback.

- (void)handleConnectionResponse:(NSError *)error

Parameters

error

Error object.

Discussion

Executes connect callback.

Declared In

YMSCBPeripheral.h

– defaultConnectionHandler

Default connection handler routine that is invoked only if connectCallback is nil.

- (void)defaultConnectionHandler

Discussion

Default connection handler routine that is invoked only if connectCallback is nil.

This method is only invoked if a connection request to an instance of this peripheral is done without a callback block defined.

Declared In

YMSCBPeripheral.h

– discoverServices:withBlock:

Discover services using block.

- (void)discoverServices:(NSArray *)serviceUUIDs withBlock:(void ( ^ ) ( NSArray *services , NSError *error ))callback

Parameters

serviceUUIDs

An array of CBUUID objects that you are interested in. Here, each CBUUID object represents a UUID that identifies the type of service you want to discover.

callback

A

Discussion

Discover services using block.

Declared In

YMSCBPeripheral.h

– objectForKeyedSubscript:

Add dictionary style subscripting to YMSCBPeripheral instance to access objects in serviceDict with key.

- (id)objectForKeyedSubscript:(id)key

Parameters

key

The key for which to return the corresponding value in serviceDict.

Return Value

object in serviceDict.

Discussion

Add dictionary style subscripting to YMSCBPeripheral instance to access objects in serviceDict with key.

Declared In

YMSCBPeripheral.h

CBPeripheralDelegate Methods

– peripheral:didDiscoverServices:

CBPeripheralDelegate implementation.

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error

Parameters

peripheral

The peripheral that the services belong to.

error

If an error occurred, the cause of the failure.

Discussion

CBPeripheralDelegate implementation.

Declared In

YMSCBPeripheral.m

– peripheral:didDiscoverIncludedServicesForService:error:

CBPeripheralDelegate implementation. Not yet supported.

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverIncludedServicesForService:(CBService *)service error:(NSError *)error

Parameters

peripheral

The peripheral providing this information.

service

The CBService object containing the included service.

error

If an error occured, the cause of the failure.

Discussion

CBPeripheralDelegate implementation. Not yet supported.

Declared In

YMSCBPeripheral.m

– peripheral:didDiscoverCharacteristicsForService:error:

CBPeripheralDelegate implementation.

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error

Parameters

peripheral

The peripheral providing this information.

service

The service that the characteristics belong to.

error

If an error occured, the cause of the failure.

Discussion

CBPeripheralDelegate implementation.

Declared In

YMSCBPeripheral.m

– peripheral:didDiscoverDescriptorsForCharacteristic:error:

CBPeripheralDelegate implementation. Not yet supported.

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverDescriptorsForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error

Parameters

peripheral

The peripheral providing this information.

characteristic

The characteristic that the characteristic descriptors belong to.

error

If an error occured, the cause of the failure.

Discussion

CBPeripheralDelegate implementation. Not yet supported.

Declared In

YMSCBPeripheral.m

– peripheral:didUpdateValueForCharacteristic:error:

CBPeripheralDelegate implementation.

- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error

Parameters

peripheral

The peripheral providing this information.

characteristic

The characteristic whose value has been retrieved.

error

If an error occured, the cause of the failure.

Discussion

CBPeripheralDelegate implementation.

Declared In

YMSCBPeripheral.m

– peripheral:didUpdateValueForDescriptor:error:

CBPeripheralDelegate implementation. Not yet supported.

- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForDescriptor:(CBDescriptor *)descriptor error:(NSError *)error

Parameters

peripheral

The peripheral providing this information.

descriptor

The characteristic descriptor whose value has been retrieved.

error

If an error occured, the cause of the failure.

Discussion

CBPeripheralDelegate implementation. Not yet supported.

Declared In

YMSCBPeripheral.m

– peripheral:didUpdateNotificationStateForCharacteristic:error:

CBPeripheralDelegate implementation. Not yet supported.

- (void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error

Parameters

peripheral

The peripheral providing this information.

characteristic

The characteristic whose value has been retrieved.

error

If an error occured, the cause of the failure.

Discussion

CBPeripheralDelegate implementation. Not yet supported.

Declared In

YMSCBPeripheral.m

– peripheral:didWriteValueForCharacteristic:error:

CBPeripheralDelegate implementation.

- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error

Parameters

peripheral

The peripheral providing this information.

characteristic

The characteristic whose value has been retrieved.

error

If an error occured, the cause of the failure.

Discussion

CBPeripheralDelegate implementation.

Declared In

YMSCBPeripheral.m

– peripheral:didWriteValueForDescriptor:error:

CBPeripheralDelegate implementation. Not yet supported.

- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForDescriptor:(CBDescriptor *)descriptor error:(NSError *)error

Parameters

peripheral

The peripheral providing this information.

descriptor

The characteristic descriptor whose value has been retrieved.

error

If an error occured, the cause of the failure.

Discussion

CBPeripheralDelegate implementation. Not yet supported.

Declared In

YMSCBPeripheral.m

– peripheralDidUpdateRSSI:error:

CBPeripheralDelegate implementation.

- (void)peripheralDidUpdateRSSI:(CBPeripheral *)peripheral error:(NSError *)error

Parameters

peripheral

The peripheral providing this information.

error

If an error occured, the cause of the failure.

Discussion

CBPeripheralDelegate implementation.

Declared In

YMSCBPeripheral.m

– peripheralDidUpdateName:

CBPeripheralDelegate implementation. Not yet supported.

- (void)peripheralDidUpdateName:(CBPeripheral *)peripheral

Parameters

peripheral

The peripheral providing this information.

Discussion

CBPeripheralDelegate implementation. Not yet supported.

iOS only.

Declared In

YMSCBPeripheral.m