EAAccessoryManager connectedAccessories returns empty array EAAccessoryManager connectedAccessories returns empty array objective-c objective-c

EAAccessoryManager connectedAccessories returns empty array


I had the same issue and was able to resolve it by adding a Supported external accessory protocols key to my info.plist file (raw key name is UISupportedExternalAccessoryProtocols). In my case, I wanted to scan for connected PayPal™ credit card terminals and Zebra™ printers. Here's the corresponding extract from my info.plist:

<key>UISupportedExternalAccessoryProtocols</key><array>    <string>com.paypal.here.reader</string>    <string>com.zebra.rawport</string></array>

Once I added these, connectedAccessories was populated.


Could you try this function?

- (void)_getAttachedDevices;{    EAAccessoryManager* accessoryManager = [EAAccessoryManager sharedAccessoryManager];    if (accessoryManager)    {        NSArray* connectedAccessories = [accessoryManager connectedAccessories];        NSLog(@"ConnectedAccessories = %@", connectedAccessories);    }    else     {       NSLog(@"No accessoryManager");    }}

Which result do you get?

Obviously remember that EAAccessory is only for the Made-For-iPod/iPhone/iPad/AirPlay licensed accessories; so if you have no licensed accessory you'll see always an empty array. Do you have a regular licensed MFI accessory?

In addiction I suggest if you haven't read it yet the Apple Documentation.

EDIT 1:

If you are still stuck try to implement the notification for connect/disconnect:

[[EAAccessoryManager sharedAccessoryManager] registerForLocalNotifications];  [[NSNotificationCenter defaultCenter] addObserver:self                                             selector:@selector(accessoryDidConnect:)                                                 name:EAAccessoryDidConnectNotification                                               object:nil];[[NSNotificationCenter defaultCenter] addObserver:self                                             selector:@selector(accessoryDidDisconnect:)                                                 name:EAAccessoryDidDisconnectNotification                                               object:nil];

Do you see the connection for your device? If yes try to get the list of connected devices on

accessoryDidConnect


Markus' answer is right, but a more subtle problem I encountered is that:

  • even if you import #import <ExternalAccessory/ExternalAccessory.h> in the m file, be sure to link it to the project: go to the app plist and in the section "Frameworks, Libraries, and Embedded Content" add ExternalAccessory.framework to the project (as indicated in the Zebra SDK documentation). I say subtle because the app don't crash, but simply return an empty connected device list.