EAAccessoryManager connectedAccessories returns an empty array

I use EAAccessoryManager to connect my application to an MFI accessory. During the initial connection, on the Bluetooth settings screen, it is displayed as a connected device.

When I try to get a list of connected devices using [accessoryManager connectedAccessories] , it returns an empty array. But when I use showBluetoothAccessoryPickerWithNameFilter , it shows me the accessory in the list.

The problem is that I do not want the user to select an accessory. I want to make this an automated process. I also included an auxiliary protocol line in info.plist. Please help me with this question. What mistake am I making here?

+8
ios objective-c iphone xcode bluetooth
source share
2 answers

Can you try this feature?

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

What result do you get?

Obviously, remember that EAAccessory is for licensed Made-For-iPod / iPhone / iPad / AirPlay accessories only; therefore, if you do not have a licensed accessory, you will always see an empty array. Do you have a regular MFI licensed accessory?

Depending on if you have not read its Apple Documentation .

EDIT 1:

If you are still stuck, try a notification to 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 a list of connected devices on

accessoryDidConnect

+1
source share

I had the same problem, and I was able to solve it by adding the Supported external accessory protocols key to my UISupportedExternalAccessoryProtocols file (the raw key name is UISupportedExternalAccessoryProtocols ). In my case, I wanted to scan connected PayPal ™ credit card terminals and Zebra ™ printers. Here is the relevant excerpt from my info.plist:

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

As soon as I added them, connectedAccessories accessories were filled.

0
source share

All Articles