13

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 ?

Rivera
  • 10,792
  • 3
  • 58
  • 102
Arun Kumar Munusamy
  • 871
  • 1
  • 10
  • 28
  • Is the device connected when it shows up in `showBluetoothAccessoryPickerWithNameFilter `? – Fennelouski Aug 11 '15 at 17:15
  • @ArunKumarMunusamy please look into this http://stackoverflow.com/questions/33388153/getting-issues-while-connecting-device-with-serial-bluetooth – Kundan Oct 29 '15 at 10:37

3 Answers3

8

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.

1

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

Massimo Polimeni
  • 4,826
  • 4
  • 27
  • 54
  • I am using the same code which was mentioned above. It's not listing out. FYI, I am trying to access a licensed MFI accessory. But when i go to the bluetooth setting screen where the accessory status showing connected and when i tap on it to reconnect again, and when i search in application, then its showing. Strange.... – Arun Kumar Munusamy Aug 12 '15 at 11:34
  • I just added the notification hint; I hope this helps. – Massimo Polimeni Aug 12 '15 at 11:53
  • Really bro.. i am using the same codes. my code works perfectly when i try to reconnect manually in settings screen as mentioned in the above comment, But during the initial connection (First time connection), i am facing this issue(array empty). I would have blamed the hardware manufacturer if it dint show me in "showBluetoothAccessoryPickerWithNameFilter" also.. – Arun Kumar Munusamy Aug 12 '15 at 12:15
  • Damn it, this is really strange. The code should work if your accessory is correctly licensed; uhm did you have try to do the obviously things (reboot, change device, ecc)? Sorry but I'm not an expert in this sector, I can't see anything else potential problem. – Massimo Polimeni Aug 12 '15 at 12:40
  • @MassimoPolimeni i am trying above code and i am able to detect it in showBluetoothAccessoryPickerWithNameFilter and pair it. But accessoryDidConnect method not getting called.Please, help me. – Kundan Oct 19 '15 at 14:21
  • @Raees: do you have register the notification for EAAccessoryDidConnectNotification? – Massimo Polimeni Oct 19 '15 at 14:55
  • @MassimoPolimeni First of all thanks for replying..Yeah i have registered for it. – Kundan Oct 19 '15 at 14:59
  • @Raees: could you open another question and post your code? Maybe add the link here here as comment – Massimo Polimeni Oct 19 '15 at 15:06
  • @MassimoPolimeni I have already opened it on apple site. https://discussions.apple.com/message/29147290#29147290 Do you want me to ask it on Stackoverflow too? – Kundan Oct 19 '15 at 15:14
  • @MassimoPolimeni opened a new question. http://stackoverflow.com/questions/33388153/getting-issues-while-connecting-device-with-serial-bluetooth – Kundan Oct 29 '15 at 10:36
1

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.
Mattia Ducci
  • 412
  • 6
  • 10