You can request to get notifications by the EAAccessoryManager
class (via registerForLocalNotifications
method). To do so, you need to add the ExternalAccessory.framework
to your project.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_accessoryDidDisconnect:) name:EAAccessoryDidDisconnectNotification object:nil];
[[EAAccessoryManager sharedAccessoryManager] registerForLocalNotifications];
Once a hardware is added, you get a notification with EAAccessoryKey
, what in turn can be used to get an EAAccessory
from the accessory manager
- (void)_accessoryDidConnect:(NSNotification *)notification {
EAAccessory *accessory = [[notification userInfo] objectForKey:EAAccessoryKey];
The accessory has a number of properties that should help to identify which kind of hardware have been connected:
NSString* name
NSString* manufacturer
NSString* modelNumber
NSString* serialNumber
NSString* firmwareRevision
NSString* hardwareRevision
NSArray* protocolStrings
I have no idea, what your audio dock provides here, but it should easy to simply try and hope that it is consistent for all devices :-)
If you are not interested in a specific device but in a class of devices (with a specific behavior), protocolStrings
should be useful. The array consists of strings that name protocols (in sense of behaviors, not in ObjectiveC sense). The names are formatted as reverse-DNS strings (com.mycompany.myprotocol).
If you provide one or more of such protocol names in the UISupportedExternalAccessoryProtocols
section (type: array of strings) of your app’s Info.plist
file, your app will be started if a proper device is connected.