iOS Developer Library

Developer

EAAccessoryManager Class Reference

Options
Deployment Target:

On This Page
Language:

EAAccessoryManager

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.

Inheritance


Conforms To


Import Statement


Swift

import ExternalAccessory

Objective-C

@import ExternalAccessory;

Availability


Available in iOS 3.0 and later.
  • Returns the shared EAAccessoryManager object for the iOS-based device.

    Declaration

    Swift

    class func sharedAccessoryManager() -> EAAccessoryManager!

    Objective-C

    + (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.

    Import Statement

    Objective-C

    @import ExternalAccessory;

    Swift

    import ExternalAccessory

    Availability

    Available in iOS 3.0 and later.

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

    Declaration

    Swift

    func registerForLocalNotifications()

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import ExternalAccessory;

    Swift

    import ExternalAccessory

    Availability

    Available in iOS 3.0 and later.

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

    Declaration

    Swift

    func unregisterForLocalNotifications()

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import ExternalAccessory;

    Swift

    import ExternalAccessory

    Availability

    Available in iOS 3.0 and later.

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

    Declaration

    Swift

    func showBluetoothAccessoryPickerWithNameFilter(_ predicate: NSPredicate!, completion completion: EABluetoothAccessoryPickerCompletion!)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import ExternalAccessory;

    Swift

    import ExternalAccessory

    Availability

    Available in iOS 6.0 and later.

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

    Declaration

    Swift

    var connectedAccessories: [AnyObject]! { get }

    Objective-C

    @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.

    Import Statement

    Objective-C

    @import ExternalAccessory;

    Swift

    import ExternalAccessory

    Availability

    Available in iOS 3.0 and later.

Data Types

  • Keys associated with the info dictionary of accessory notifications.

    Declaration

    Swift

    let EAAccessoryKey: NSString! let EAAccessorySelectedKey: NSString!

    Objective-C

    NSString *const EAAccessoryKey; NSString *const EAAccessorySelectedKey;

    Constants

    • EAAccessoryKey

      EAAccessoryKey

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

      Available in iOS 3.0 and later.

    • EAAccessorySelectedKey

      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.

  • Constants associated with the Bluetooth picker.

    Declaration

    Swift

    let EABluetoothAccessoryPickerErrorDomain: NSString!

    Objective-C

    NSString *const EABluetoothAccessoryPickerErrorDomain;

    Constants

    • EABluetoothAccessoryPickerErrorDomain

      EABluetoothAccessoryPickerErrorDomain

      The domain for errors passed to a EABluetoothAccessoryPickerCompletion block.

      Available in iOS 6.0 and later.

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

    Declaration

    Swift

    enum EABluetoothAccessoryPickerErrorCode : Int { case AlreadyConnected case ResultNotFound case ResultCancelled case ResultFailed }

    Objective-C

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

    Constants

    • AlreadyConnected

      EABluetoothAccessoryPickerAlreadyConnected

      The specified accessory was already connected.

      Available in iOS 6.0 and later.

    • ResultNotFound

      EABluetoothAccessoryPickerResultNotFound

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

      Available in iOS 6.0 and later.

    • ResultCancelled

      EABluetoothAccessoryPickerResultCancelled

      The user canceled the picker alert.

      Available in iOS 6.0 and later.

    • ResultFailed

      EABluetoothAccessoryPickerResultFailed

      Selecting an accessory failed for an unknown reason.

      Available in iOS 6.0 and later.

    Import Statement

    Objective-C

    @import ExternalAccessory;

    Swift

    import ExternalAccessory

    Availability

    Available in iOS 6.0 and later.

  • 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 EAAccessoryKey, 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.

    Import Statement

    Objective-C

    @import ExternalAccessory;

    Swift

    import ExternalAccessory

    Availability

    Available in iOS 3.0 and later.

  • 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 EAAccessoryKey, 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.

    Import Statement

    Objective-C

    @import ExternalAccessory;

    Swift

    import ExternalAccessory

    Availability

    Available in iOS 3.0 and later.