iPad shows bluetooth accessory connected, but EAAccessoryManager doesn't find it?
Asked Answered
F

3

7

This is driving me nuts...I had it working fine before and have no idea what has changed. I'm connecting to a proprietary company device over bluetooth, it has the auth chip and (as I said) everything was fine before.

My iPad and the accessory both show that they are connected to each other. Yet when I try to talk to the device within my app, most of the time EAAccessoryManager doesn't even find it...but once in a while I can connect. What gives?

-(void)scanForDevice
{

NSArray *accList = [[EAAccessoryManager sharedAccessoryManager] connectedAccessories];

// This is ZERO every time...even though iPad and device both indicate connection.
DLog(@"accList count: %i", accList.count);

for (EAAccessory *accessory in accList)
{
    for (NSString* protocolString in accessory.protocolStrings) {
        if ([protocolString isEqualToString:[redacted]]) {
            [self connectToAccessory:accessory];
            break;
            }
        }
    }
}

ETA: I have since wired up a button to call the showBluetoothAccessoryPicker... method to show a Bluetooth picker within the app. This resulted in even more confusion. The accessory that the iPad is telling me I'm already connected to (in settings) shows up in the picker. When I click it, console output is as follows:

2014-04-01 16:48:00.324 Subview[3438:60b] BTM: attempting to connect to service 0x00000080 on device [redacted] 00:07:80:73:06:01
2014-04-01 16:48:02.497 Subview[3438:60b] BTM: connection to service 0x00000080 on device [redacted] 00:07:80:73:06:01 succeeded
2014-04-01 16:48:11.924 Subview[3438:60b] BTM: lost device [redacted] 00:07:80:73:06:01
2014-04-01 16:48:12.500 Subview[3438:60b] BTM: setting pairing disabled
2014-04-01 16:48:12.501 Subview[3438:60b] BTM: disabling device scanning
2014-04-01 16:48:12.509 Subview[3438:60b] <0x157d10770 JobListViewController.m:(255)> BTPicker failed with error: The operation couldn’t be completed. (EABluetoothAccessoryPickerErrorDomain error 1.) 

That error code shows up in the docs as "Not found". Hmm...so the connection succeeds, then it's immediately lost, then it's not found, even though according to settings I was connected the entire time? I am a loss to explain any of this. Would greatly appreciate any help with someone who is experienced in this framework. I am almost completely convinced that it's either a problem with the framework, with the accessory itself, or some combination thereof.

Frankpledge answered 4/3, 2014 at 18:27 Comment(4)
Does it states connected in Settings.app? Did you try forget it there and redo the pairing?Pumice
Yep...iPad shows it as connected to accessory. Accessory shows it is connected to iPad. [[EAAccessoryManager sharedAccessoryManager] connectedAccessories] returns a big fat zero. Forgetting and re-pairing sometimes works, sometimes doesn't. Now I'm getting an additional bug where the accessory "un-connects" itself after a couple of seconds. My conclusion: Bluetooth sucks, and always has, and there's nothing I can do about it. Doesn't help that nobody out there even works with this framework because Core Bluetooth with BTLE is superior and far easier...but not an option for me here.Frankpledge
@ReidBelton: By any chance, did you get solution for this ??Uriniferous
@ReidBelton If you got the solution for this, then post it.. I am also facing the same issue. ThanksAlbright
G
1

Did you add a protocol string for your accessory into Supported External Accessory protocols of Info.plist? Documentation says:

The picker displays only Bluetooth devices that include an iAP over Bluetooth unique ID in their extended inquiry response.

In my case, unfortunately, I don't know a protocol string for my device, so I can't prove if my advice will work. But it's better than nothing.

Gink answered 2/2, 2016 at 7:12 Comment(0)
A
1

Refer to https://forums.developer.apple.com/thread/61646. Something change after iOS 10 for security reasons. Otherwise, you can use iOS device with earlier os version to get the protocol string of your accessory(property “protocolStrings” for class "EAAccessory"), then add the protocol string into plist for key "Supported External Accessory protocols".

Ames answered 17/2, 2017 at 2:30 Comment(1)
Though that wasn't my issue 2 years ago when I asked this, it is correct and the most likely cause for someone who stumbles on this question. Also note that protocol strings are now case-sensitive!Frankpledge
K
0

Have you tried using the CoreBluetooth framework? Although this is only for BLE devices.

Kleinstein answered 28/3, 2014 at 20:23 Comment(1)
Can't do that unfortunately as the proprietary device I'm trying to talk to is set up to use MFI over regular Bluetooth (development on it started before BLE was available on iOS). Otherwise I would most definitely be using Core Bluetooth as it seems much more straightforward (and reliable). Thanks though...you still get an up-vote because for most other people it would definitely make more sense to use BLE/Core Bluetooth :)Frankpledge

© 2022 - 2024 — McMap. All rights reserved.