At work, I was given the mission :) to port an Android Library that connects to a device to do things (I can't say much more because of NDA). The Android code uses getRemoteDevice(macAddress)
and createRfcommSocketToServiceRecord
to basically skip the whole pairing mechanism and then send bytes "as is". Is this possible on iOS? Is there this level of "dirtyness" :-)

- 4,137
- 2
- 33
- 32
-
Is it Bluetooth Low Energy or Bluetooth 2.1? – Paulw11 Aug 15 '14 at 12:13
-
@Paulw11: the device does both. Ideally my boss wants me to do this in 2.1 but I can probably easily "sell" them to do LE. Why do you specifically ask? – StuFF mc Aug 15 '14 at 18:17
-
2Because under iOS you nee to go through the Apple Made For iPhone (MFi) program to talk to a Bkuetooth 2.1 device, but BLE is supported by the Core Bluetooth framework with no involvement from Apple. The downside of BLE is that it won't work on devices earlier than iPhone 4S or iPad 3 – Paulw11 Aug 15 '14 at 21:13
2 Answers
If it is Bluetooth 2.1 then it is pretty easy. You also can create sockets. For example:
EASession *session = [[EASession alloc] initWithAccessory:accessory
forProtocol:PROTOCOL_STRING];
if (session) {
[[session inputStream] setDelegate:self];
[[session inputStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[[session inputStream] open];
[[session outputStream] setDelegate:self];
[[session outputStream] scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[[session outputStream] open];
}
But, as @Paulw11 mentioned, you need to go through MFI program.
Bluetooth LE is a lot different. It does not have sockets. You can only operate with services and characteristics.
And by the way you cannot connect to BLE device only by using its MAC address. You first need to scan for this device using its service UUID:
[_centralManager scanForPeripheralsWithServices:@[[CBUUID UUIDWithString:kScanServiceUUID]] options:options];
And only after that connect to its CBPeripheral.
UPDATE: And what about "to basically skip the whole pairing mechanism" in Bluetooth 2.1, I guess you cannot just do pairing without user. There is one method that shows dialog to user and he can select device that he wants to pair, but that is all I could find:
- (void)showBluetoothAccessoryPickerWithNameFilter:(NSPredicate *)predicate completion:(EABluetoothAccessoryPickerCompletion)completion
Displays an alert that allows the user to pair the device with a Bluetooth accessory.
Unlike Bluetooth 2.1, in Bluetooth LE you do not need pairing at all.

- 111
- 4
Unless you have control over the device firmware, this cannot be done via CoreBluetooth. (Which only talks BT 4.0.) I beat my head against this for weeks and there seems to be no way around this in a manner which would pass muster in the App Store review process. Additionally, the Bluetooth 4.0 std specifically says the MAC address is not fixed and the device may change it on you.
However, if you have control over what goes into the GATT, you can probably fake what android is doing.
I do not know what interfaces are available on the MFI program and whether they may be more amenable to your goals.

- 2,124
- 14
- 13