Monitoring Accessory-Related Events
The External Accessory framework is capable of sending notifications whenever a hardware accessory is connected or disconnected. Although it is capable, it does not do so automatically. Your app must specifically request that notifications be generated by calling the
registerForLocalNotifications method of the
EAAccessoryManager class. When an accessory is connected, authenticated, and ready to interact with your app, the framework sends an
EAAccessoryDidConnectNotification notification. When an accessory is disconnected, it sends an
EAAccessoryDidDisconnectNotification notification. You can register to receive these notifications using the default
NSNotificationCenter, and both notifications include information about which accessory was affected.
In addition to receiving notifications through the default notification center, an app that is currently interacting with an accessory can assign a delegate to the corresponding
EAAccessory object and be notified of changes. Delegate objects must conform to the
EAAccessoryDelegateprotocol, which currently contains the optional
accessoryDidDisconnect: method. You can use this method to receive disconnection notices without first setting up a notification observer.
If your app is suspended in the background when an accessory notification arrives, that notification is put in a queue. When your app begins running again (either in the foreground or background), notifications in the queue are delivered to your app. Notifications are also coalesced and filtered wherever possible to eliminate any irrelevant events. For example, if an accessory was connected and subsequently disconnected while your app was suspended, your app would ultimately not receive any indication that such events took place.
For more information about how to register to receive notifications, see Notification Programming Topics.