tutorial - ios swift bluetooth example

iOS BLE Bluetooth-send/receive HEX data (2)

I am creating an iOS application that should connect to a custom BLE device. I need to iOS app to send 2 HEX commands, one to enable a part of the device and another to request for Data.

Is there any way in iOS to send/receive custom HEX data, other than working with services & characteristics?

No that is not possible, but the reason for this is not iOS but that the 'services' and 'characteristics' are just part of how the BLE protocol is defined.

Official spec: https://developer.bluetooth.org/TechnologyOverview/Pages/BLE.aspx

Generic Attribute Profile

The latest Bluetooth specification uses a service-based architecture based on the attribute protocol (ATT). All communication in low energy takes place over the Generic Attribute Profile (GATT). An application or another profile uses the GATT profile so a client and server can interact in a structured way.

The server contains a number of attributes, and the GATT Profile defines how to use the Attribute Protocol to discover, read, write and obtain indications. These features support a service-based architecture. The services are used as defined in the profile specifications. GATT enables you to expose service and characteristics defined in the profile specification.

The other answer is accidentally right, but for the wrong reasons.

Of course it is possible in BLE to send any kind of data, not just GATT. It's just that iOS forces you to work with GATT. There are no iOS APIs for anything else. So, yes, it is iOS that prevents you from doing it.

If you wouldn't be forced to work with GATT, there would be some other options:

  • L2CAP Credit-Based Channels - you create a channel that allows you to send full 23 octets of data per packet (that's in BLE 4.0 and 4.1; 4.2 allows more than that), in whatever format you choose to.
  • With access to the HCI, you can send a custom ACL Data Packet to avoid the L2CAP header. But you need to also modify the other side to make sure it parses it correctly.