External Accessory Bluetooth iPad app does not work on Silicon Mac

I'm using the External Accessory API to communicate with Bluetooth MFI device in my iOS app. It works perfect on iPhone/iPad, but does not work when I run the app on a M1/M2 Silicon Mac.

The code I use is: EAAccessoryManager accessoryManager = EAAccessoryManager.SharedAccessoryManager; EAAccessory[] accessories = accessoryManager.ConnectedAccessories;

The supported accessory protocols are properly defined in info.plist. This code works perfect on iOS devices, but always returns 0 connected accessories when app is executed on a M1/M2 silicon Mac. Is there something that I have to add to info.plist?

The supported accessory protocols are properly defined in info.plist. This code works perfect on iOS devices, but always returns 0 connected accessories when app is executed on a M1/M2 silicon Mac. Is there something that I have to add to info.plist?

No, the issue is more complicated than that. I don't have an accessory at hand to confirm this, but I think the problem here is actually the pairing process. On iOS, you'd use "showBluetoothAccessoryPicker" to pair the accessory, but on the mac that method:

"On Apple silicon, this method displays an alert to let the user know that the Bluetooth accessory picker is unavailable."
_
And:

"iPhone and iPad apps running on Macs with Apple silicon never receive this notification."
_

Finally, looking at out code, I'm not sure EAAccessoryManager (on the mac) will pickup new accessories automatically when they're attached. I think it will pick them up when the app foregrounds, but I don't think it will detect them until them.

SO, what I would actually do here is:

  1. Quit your app (so none of your code is running).

  2. Manually pair/connect to your accessory through Bluetooth settings.

  3. Launch your app and check "connectedAccessories".

I don't have an accessory at hand to test this with, but I think that's the flow that's most likely to work.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Thank you for the quick answer.

I'm not using the BluetoothPicker. Instead, I ask the users to pair the Bluetooth adapter to their iOS device before using the app.

The Bluetooth pairing process on MacOS (I updated to the latest v14.5) also seems a bit weird - it asks for PIN code confirmation, but almost immediately closes that confirmation window (without a chance to click OK). After that the Bluetooth adapter is displayed as "Connected" for about a second and then switches to "Not connected" state.

Anyway, I tried your suggestion to start the app while it is in "connected" state... tried many times, but no luck, the "ConectedAccessories" always returns 0 accessories.

I also found this page https://developer.apple.com/documentation/externalaccessory which clearly states "iPad and iPhone apps running on a Mac with Apple silicon can’t connect to external accessories using this framework. You may continue to link apps to this framework and run other features on Apple silicon."... So, I guess that it won't be possible to connect to these Bluetooth devices using External Accessory.

So, the question now is:

Is there a different way to connect and use a MFI Bluetooth device that would work on a Silicon Mac?

The devices are MFI certified Bluetooth OBD adapters.

I also found this page https://developer.apple.com/documentation/externalaccessory which clearly states "iPad and iPhone apps running on a Mac with Apple silicon can’t connect to external accessories using this framework. You may continue to link apps to this framework and run other features on Apple silicon."...

Wait, what kind of app were you testing with? Were you using the "iOS on macOS" compatibility layer? Or was this a "native" app (either Mac Catalyst or AppKit). This terminology "iPad and iPhone apps running on a Mac" generally means "apps running through the compatibility layer". If the framework didn't work at all, we would have just left of macOS support. Similarly, we wouldn't have include the warnings about the bluetooth picker on macOS if bluetooth didn't work at all. Before you give up on this entirely, I'd recommend testing this in fully "native" app.

I'm not using the BluetoothPicker. Instead, I ask the users to pair the Bluetooth adapter to their iOS device before using the app.

I assume you meant macOS here, correct? Also, you should be testing the accessory with the mac being the ONLY accessory that's paired with it. Honestly, I'd probably turn of bluetooth on "everything" around me except the mac. See comments below for more on that point...

Having said that:

Is there a different way to connect and use a MFI Bluetooth device that would work on a Silicon Mac?

That depends on how exactly the accessory works. Lots of accessories are multiplatform, which typically means they implement multiple communication "paths"- one for MFI and a different one for other platforms. That might sound like extra work/effort, but most of the hardware controllers have plenty of unused "capacity" for this and most of these accessories only support one connection at a time, so the extra interface isn't doesn't actually create more "work".

As a side note on that, make sure you've unpaired/disconnected the accessory from anything else. If another controller (like your iPhone) was also active, I could see that causing this kind of thing**:

The Bluetooth pairing process on MacOS (I updated to the latest v14.5) also seems a bit weird - it asks for PIN code confirmation, but almost immediately closes that confirmation window (without a chance to click OK). After that the Bluetooth adapter is displayed as "Connected" for about a second and then switches to "Not connected" state.

**As an even broader comment, if you haven't worked with hardware before one of the best tips I can give is to do EVERYTHING you can to make the configuration as simple as possible and rule out ANY failure you can think of. From painful experience, it's FAR to easy to waste lots of time "investigating" something, only to discover that the ACTUAL problem was a dumb quirk/side effect that you could have just avoided by tweaking your configuration.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Sorry that I did not explain it more clear.

It is an iOS app (for iPhone and iPad) and it is not a new one. It is working without issues for many years. We develop it on Visual Studio for Mac and use the Xamarin framework.

Recently (with the release of M1 MacBooks) apple added possibility to run the iOS apps directly on these M1/M2 Silicon MacBooks without any modification.

We test the released app by downloading from app store on our test MacBooks. I know it is not the best approach, but unlike Xcode, Visual Studio does not have an option to test on M1/M2 MacBook simulator while developing.

Fortunately, the app works perfectly fine on Mac except for this issue with the MFI devices. Our app is a vehicle tool that uses these hardware OBD devices to communicate with the vehicle systems. The app can work with different OBD devices. We support various WiFi, BLE and MFI Bluetooth devices and all of them work perfect when running the app on an iPhone or iPad. On MacBook - communicating with BLE or WiFi devices also works fine. Ironically, only the special "designed for Apple" MFI Bluetooth devices cause problems.

We use the most simple way for communication with these MFI Bluetooth accessory devices: Simply use "accessoryManager.ConnectedAccessories" to get a list of the paired/available devices and then open connection with the first available. Of course, we also defined the correct protocols in info.plist.

Recently (with the release of M1 MacBooks) apple added possibility to run the iOS apps directly on these M1/M2 Silicon MacBooks without any modification.

OK. As I mentioned previously, the External Accessory framework will not work through that compatibility layer. That was a core design choice the framework made, primarily because the additional layering in the compatibility layer made it very difficult for the macOS infrastructure layer and the iOS support layer to coordinate accessory access in a reasonable way.

We develop it on Visual Studio for Mac and use the Xamarin framework.

I don't the the full details of what this entails, but Xamarin does support creating "native" macOS apps, so that's what I'd recommend doing here. I don't think you'd have any issue with this is a native app.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

External Accessory Bluetooth iPad app does not work on Silicon Mac
 
 
Q