PTDBeanManager Class Reference

Inherits from NSObject
Declared in PTDBeanManager.h

Overview

Manages discovery and connection of Beans

 Example:

 //Put the following code in your class initialization
 {
    PTDBeanManager* beanManager;
    // create the Bean Manager and assign ourselves as the delegate
    beanManager = [[PTDBeanManager alloc] initWithDelegate:self];
 }

 // check to make sure we're on
 - (void)beanManagerDidUpdateState:(PTDBeanManager *)manager{
   if(beanManager.state == BeanManagerState_PoweredOn){
     // if we're on, scan for advertisting beans
     NSError* scanError;
     [beanManager startScanningForBeans_error:&scanError];
     if (scanError) {
        NSLog(@"%@", [scanError localizedDescription]);
     }
   }
   else if (beanManager.state == BeanManagerState_PoweredOff) {
     // do something else
   }
 }
 // bean discovered
 - (void)beanManager:(PTDBeanManager*)beanManager didDiscoverBean:(PTDBean*)bean error:(NSError*)error{
   if (error) {
     NSLog(@"%@", [error localizedDescription]);
     return;
   }
   NSError* connectError;
   [beanManager connectToBean:bean error:&connectError];
   if (connectError) {
     NSLog(@"%@", [connectError localizedDescription]);
   }
 }
 // bean connected
 - (void)beanManager:(PTDBeanManager*)beanManager didConnectToBean:(PTDBean*)bean error:(NSError*)error{
   if (error) {
     NSLog(@"%@", [error localizedDescription]);
     return;
   }
   // do stuff with your Bean
 }

Monitoring Properties

  delegate

  • The delegate object for the BeanManager. Assign your class as this delegate to receive delegate messages.
@property (nonatomic, weak) id<PTDBeanManagerDelegate> delegate

Declared In

PTDBeanManager.h

  state

The BeanManagerState state of the BeanManager. Tells you if the Bluetooth Adapter is of, off, unknown, etc.

@property (nonatomic, assign, readonly) BeanManagerState state

Declared In

PTDBeanManager.h

Initializing a Bean Manager

– initWithDelegate:

Initializes the BeanManager with a delegate that implements the PTDBeanManagerDelegate protocol.

- (instancetype)initWithDelegate:(id<PTDBeanManagerDelegate>)delegate

Parameters

delegate

the delegate for this object

Return Value

an instance of the BeanManager

Declared In

PTDBeanManager.h

– initWithDelegate:stateRestorationIdentifier:

Initializes the BeanManager with a delegate that implements the PTDBeanManagerDelegate protocol with state restoration (iOS only).

- (instancetype)initWithDelegate:(id<PTDBeanManagerDelegate>)delegate stateRestorationIdentifier:(NSString *)stateRestorationIdentifier

Parameters

delegate

the delegate for this object

stateRestorationIdentifier

the CoreBluetooth state restoration identifier

Return Value

an instance of the BeanManager

Declared In

PTDBeanManager.h

Scanning or Stopping Scans for Beans

– startScanningForBeans_error:

Begins scanning for Beans

- (void)startScanningForBeans_error:(NSError **)error

Parameters

error

Nil if successful. See BeanErrors for error codes.

Declared In

PTDBeanManager.h

– stopScanningForBeans_error:

Stops scanning for Beans

- (void)stopScanningForBeans_error:(NSError **)error

Parameters

error

Nil if successful. See BeanErrors for error codes.

Declared In

PTDBeanManager.h

Establishing or Canceling Connections with Beans

– connectToBean:error:

Connects to a Bean

- (void)connectToBean:(PTDBean *)bean error:(NSError **)error

Parameters

bean

The Bean to connect to

error

Nil if successful. See BeanErrors for error codes.

Declared In

PTDBeanManager.h

– connectToBean:withOptions:error:

Connects to Bean

- (void)connectToBean:(PTDBean *)bean withOptions:(NSDictionary *)options error:(NSError **)error

Parameters

bean

The Bean to connect to

options

A dictionary of connection options

error

Nil if successful. See BeanErrors for error codes.

Declared In

PTDBeanManager.h

– disconnectBean:error:

Disconnects from a Bean. This will cancel any firmware update in progress.

- (void)disconnectBean:(PTDBean *)bean error:(NSError **)error

Parameters

bean

The Bean to disconnect from

error

Nil if successful. See BeanErrors for error codes.

Declared In

PTDBeanManager.h

– disconnectFromAllBeans:

Disconnects all connected Beans

- (void)disconnectFromAllBeans:(NSError **)error

Parameters

error

Nil if successful. See BeanErrors for error codes.

Declared In

PTDBeanManager.h