Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 445
Reid Avatar asked Mar 04 '14 18:03

Reid


2 Answers

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.

like image 114
slashdot Avatar answered Oct 17 '22 00:10

slashdot


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".

like image 26
suhuaidong Avatar answered Oct 17 '22 01:10

suhuaidong