How to list out all MFI devies into the iOS app?
Asked Answered
Y

1

8

I want to display the list of all MFI passed apple devices which are not paired before from iOS settings.

I can list out the connected devices using below code:

NSArray *accessories = [[EAAccessoryManager sharedAccessoryManager]

                               connectedAccessories];

So My Query is:

  1. Can i scan all the available unpaired MFI devices using "External Accessories" framework in to the iOS app and then i can pair them from the iOS app.

Please help me for shorting this out.

Lots of thanks in advance.....

Yehudit answered 18/12, 2013 at 9:26 Comment(0)
N
17

Yes, You can.

From iOS 6 EA Framework provides built-in bluetooth pairing function within app.

Check this:

[[EAAccessoryManager sharedAccessoryManager] showBluetoothAccessoryPickerWithNameFilter:nil completion:^(NSError *error) {

}];

You can also use filter parameters to filter your devices.

But remember, if you send or receive data from device via MFI, you may need to add protocol string into Info.plist on "Supported external accessory protocols"

Edit:

OK, I will list step by step of MFI world.

1.What above code is doing?

It pops up a small tableView to show all available Bluetooth devices.

2.How to pair?

Just click a cell shown in the table. It will automatically connect to device.

3.How to identify device is paired or not?

Check following code, You should understand what is it.

[[EAAccessoryManager sharedAccessoryManager] showBluetoothAccessoryPickerWithNameFilter:nil completion:^(NSError *error) {
        if (error) {
            NSLog(@"error :%@", error);
        }
        else{
            NSLog(@"You make it! Well done!!!");
        }
    }];

4.Notification connect or disconnect?

Check the following notifications.

EAAccessoryDidConnectNotification
EAAccessoryDidDisconnectNotification

There are a lot things you can research on MFI, so it is better go through Apple documents and example code to understand it deeply.

Nones answered 18/12, 2013 at 9:30 Comment(5)
Thanks brianLikeApple, I have used this method but now my app is crashing. Can you please explain this by step by step like: What code i should write in completion block? How the list of device will be displayed? How to pair the device? How i identify device is paired successfully? and if device is disconnected how app will notifies me that device is no longer be connected? Please help me i am going to accept your answer....Yehudit
I have implemented this method but it is not showing any table view on the screen. I have put this code in -()viewDidLoad method. So i need to change any thing in this code?Yehudit
No you don't need. Have you add EA Framework to your project? And also import .h Header? Or delay to call this methods after viewDidView using:[NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(showBTTalbe) userInfo:nil repeats:NO];Nones
@Yehudit I just want to modify my words that you can only show available device on the table, not all. Thanks.Nones
Unfortunately this no longer works with the "new" Scene-based mechanism. It's broken since iOS13Pantaloons

© 2022 - 2024 — McMap. All rights reserved.