EAAccessoryManager Class Reference

Inherits from
Conforms to
Availability
Available in iOS 3.0 and later.
Declared in
EAAccessoryManager.h
Related sample code

Overview

The EAAccessoryManager class coordinates the attached accessories for an iOS-based device. You use this class to retrieve a list of accessories to which your application might want to connect. You also use this class to start and stop the sending of accessory-related connect and disconnect notifications.

Tasks

Getting the Shared Accessory Manager

Starting and Stopping Accessory Notifications

Presenting the Bluetooth Picker

Getting the Available Accessories

Properties

connectedAccessories

The accessory objects corresponding to the list of currently connected accessories. (read-only)

@property (nonatomic, readonly) NSArray *connectedAccessories;
Discussion

This property contains an array of EAAccessory objects. Each object corresponds to an accessory that is connected and available for your application to use. Because the contents of this property can change dynamically based on the connection and disconnection of accessories, you should not cache the value of this property.

Availability
  • Available in iOS 3.0 and later.
Related Sample Code
Declared In
EAAccessoryManager.h

Class Methods

sharedAccessoryManager

Returns the shared EAAccessoryManager object for the iOS-based device.

+ (EAAccessoryManager *)sharedAccessoryManager
Return Value

The shared accessory manager object.

Discussion

You should always use this method to obtain the accessory manager object and should not try to create instances directly.

Availability
  • Available in iOS 3.0 and later.
Related Sample Code
Declared In
EAAccessoryManager.h

Instance Methods

registerForLocalNotifications

Begins the delivery of accessory-related notifications to the current application.

- (void)registerForLocalNotifications
Discussion

You must call this method if you want to be notified when accessories become connected or disconnected. The system does not send these notifications automatically, so calling this method lets the system know that your application is interested in them. Typically, you would call this method only once early in your application, either before or after configuring your notification observers. When you no longer need to monitor these notifications, you should call the matching unregisterForLocalNotifications method.

You can configure your notification observers either before or after calling this method. Because the shared accessory manager is the only object that sends accessory-related notifications, specifying that object or nil for the notification sender has the same outcome.

Availability
  • Available in iOS 3.0 and later.
Related Sample Code
Declared In
EAAccessoryManager.h

showBluetoothAccessoryPickerWithNameFilter:completion:

Displays an alert that allows the user to pair the device with a Bluetooth accessory.

- (void)showBluetoothAccessoryPickerWithNameFilter:(NSPredicate *)predicate completion:(EABluetoothAccessoryPickerCompletion)completion
Parameters
predicate

The predicate is evaluated using the name of the Bluetooth accessory. Only devices whose names match the predicate are displayed by the picker. If you specify nil, this method displays all discovered accessories.

completion

A completion block to execute when the picker is dismissed. You can use this block to track any errors that might have occurred during the pairing process.

Discussion

This method synchronously displays an alert containing the list of Bluetooth accessories that have been discovered by the current device and that match the specified filter (if any). The user can select an accessory from this list and pair the device to it. Pairing an accessory updates the accessory manager’s list of connected accessories and generates a corresponding connection notification.

Availability
  • Available in iOS 6.0 and later.
Declared In
EAAccessoryManager.h

unregisterForLocalNotifications

Stops the delivery of accessory-related notifications to the current application.

- (void)unregisterForLocalNotifications
Discussion

Typically, you would call this method either when your application exits or when you no longer want to receive accessory-related notifications. Calls to this method must be balanced with a preceding call to the registerForLocalNotifications method.

Availability
  • Available in iOS 3.0 and later.
Declared In
EAAccessoryManager.h

Constants

Notification User Info Keys

Keys associated with the info dictionary of accessory notifications.

NSString *const EAAccessoryKey;
NSString *const EAAccessorySelectedKey;
Constants
EAAccessoryKey

The value assigned to this key is the EAAccessory object whose status changed.

Available in iOS 3.0 and later.

Declared in EAAccessoryManager.h.

EAAccessorySelectedKey

The value assigned to this key is the EAAccessory object that was selected by the user. This key is included in the info dictionary when the user pairs a Bluetooth accessory with the device using the Bluetooth picker.

Available in iOS 6.0 and later.

Declared in EAAccessoryManager.h.

EABluetoothAccessoryPickerCompletion

The completion block for the Bluetooth picker.

typedef void(^EABluetoothAccessoryPickerCompletion)(NSError *error);
Discussion

You use this block to process results generated by the showBluetoothAccessoryPickerWithNameFilter:completion: method. The block receives an NSError object as its only parameter. If no error occurred, this parameter is set to nil.

Availability
  • Available in iOS 6.0 and later.
Declared In
EAAccessoryManager.h

Accessory Picker Error Domain

Constants associated with the Bluetooth picker.

NSString *const EABluetoothAccessoryPickerErrorDomain;
Constants
EABluetoothAccessoryPickerErrorDomain

The domain for errors passed to a EABluetoothAccessoryPickerCompletion block.

Available in iOS 6.0 and later.

Declared in EAAccessoryManager.h.

EABluetoothAccessoryPickerErrorCode

The error codes that may be passed in an error object to a EABluetoothAccessoryPickerCompletion block.

enum {
   EABluetoothAccessoryPickerAlreadyConnected,
   EABluetoothAccessoryPickerResultNotFound,
   EABluetoothAccessoryPickerResultCancelled,
   EABluetoothAccessoryPickerResultFailed
};
typedef NSInteger EABluetoothAccessoryPickerErrorCode;
Constants
EABluetoothAccessoryPickerAlreadyConnected

The specified accessory was already connected.

Available in iOS 6.0 and later.

Declared in EAAccessoryManager.h.

EABluetoothAccessoryPickerResultNotFound

The specified accessory could not be found, perhaps because it was turned off prior to connection.

Available in iOS 6.0 and later.

Declared in EAAccessoryManager.h.

EABluetoothAccessoryPickerResultCancelled

The user canceled the picker alert.

Available in iOS 6.0 and later.

Declared in EAAccessoryManager.h.

EABluetoothAccessoryPickerResultFailed

Selecting an accessory failed for an unknown reason.

Available in iOS 6.0 and later.

Declared in EAAccessoryManager.h.

Notifications

EAAccessoryDidConnectNotification

Posted when an accessory becomes connected and available for your application to use.

The notification object is the shared accessory manager. The userInfo dictionary contains an EAAccessorySelectedKey, whose value is an EAAccessory object representing the accessory that is now connected. If a Bluetooth accessory was selected by the user in the Bluetooth picker, this dictionary contains the EAAccessorySelectedKey key. Before delivery of this notification can occur, you must call the registerForLocalNotifications method to let the system know you are interested in receiving this notification.

Availability
Declared In
EAAccessoryManager.h

EAAccessoryDidDisconnectNotification

Posted when an accessory is disconnected and no longer available for your application to use.

The notification object is the shared accessory manager. The userInfo dictionary contains an EAAccessorySelectedKey, whose value is the EAAccessory object representing the accessory that was disconnected. Before delivery of this notification can occur, you must call the registerForLocalNotifications method to let the system know you are interested in receiving this notification.

If your accessory manager has a delegate, the delegate can use the accessoryDidDisconnect: method to receive this notification instead.

Availability
Declared In
EAAccessoryManager.h