Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EAAccessoryManager connectedAccessories returns empty array

I am using EAAccessoryManager to connect my application to a MFI accessory. During the initial connection, in bluetooth setting screen, it showing as device connected.

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

The problem is i don't want user to choose the accessory. I want to make this a automated process. I have included the accessory protocol string in info.plist too. Please guide me with this issue. What mistake i am doing here ?

like image 870
Arun Kumar Munusamy Avatar asked Aug 04 '15 13:08

Arun Kumar Munusamy


2 Answers

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.

like image 182
Markus Schneider Avatar answered Oct 30 '22 14:10

Markus Schneider


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

like image 20
Massimo Polimeni Avatar answered Oct 30 '22 13:10

Massimo Polimeni