user1219432
user1219432

Reputation: 153

Get the MAC address of a Bluetooth device with Apples "External Accessory framework"

I have a Bluetooth device that is Apple compatible.

Now, I'm trying to get the MAC address of that device within an app. Is it possible to get the MAC address of a Bluetooth device with the help of Apples "External Accessory framework"?

I heard that it's not possible to get the MAC address the normal way, but I don't understand the "External Accessory framework" good enough to decide if it's possible with this framework or not.

Upvotes: 4

Views: 3509

Answers (3)

FormigaNinja
FormigaNinja

Reputation: 1571

No, you can't get the EAAccessory's mac address. I mean, you can using the command below:

NSString *macAddress = [accessory valueForKey:@"macAddress"];

But it's not documented as you can see on EAAccessory documents. Apple can reject your app or this function could stop working on the next iOS update etc.

If you are just trying to make a custom action on a specific model of device, in most of cases you could use one of the available info:

<EAAccessory: 0x17445c180> {
  connected:YES
  connectionID:29354791
  name: 23HG YKL CXN
  manufacturer: MANUFACTURER NAME
  modelNumber: 878253-222
  serialNumber: //not always available
  firmwareRevision: 1.0.0
  hardwareRevision: 1.0.0
  protocols: (
    "com.some.protocol",
    "com.some.other.protocol"
  )
}

Or a mix of it like (modelNumber + firmwareRevision) etc.

PS: I know that with info above, you don't know the difference between two identical devices, but depending on what kind of app you are developing, it doesn't matter anyway.

Hope it helps.

Upvotes: 5

Tommaso Resti
Tommaso Resti

Reputation: 5950

Try this:

NSString *macAddress = [accessory valueForKey: @"macAddress"];

but i noticed this only work whit newest devices. (iPad 1's accessory is not key value coding-compliant for the key 'macAddress')

Take a look into the entire accessory dictionary for more keys:

NSLog(@"%@", accessory);

Upvotes: 1

RLH
RLH

Reputation: 15698

The short answer is no, you can't do that.

The reason is because all that the External Accessory framework does is setup input and output data streams with the device. If you want to acquire the MAC address from the hardware, the hardware has to provide that information through whatever communication mechanism they have created for their devices and there related iOS software.

Upvotes: 0

Related Questions