Differences between CBUUID and NSUUID in Fast

Where are the differences between CBUUID and NSUUID?

I saw to populate scanForPeripheralsWithServices with both objects in different cases ... Apple expects a CBUUID object, so would I prefer to use this type or?

My example:

let MY_SERVICE_UUID = CBUUID(string: "hdl83h6sd-gl95-bn4f-37gd-jd73hd0tn8za") func scanForPeripheralsWithServices(serviceUUIDs: MY_SERVICE_UUID,nil)

+6
source share
1 answer

An NSUUID is a 128-bit number that is used to uniquely identify objects, types, and other elements. It can be accessed as bytes or is usually used in string form - 68753A44-4D6F-1226-9C60-0050E4C00067. The class includes methods for creating both random UUIDs and instances initialized with a special value.

Bluetooth also uses 128-bit identifiers for features and services. Bluetooth SIG has identified many β€œwell-known” services and features. They are represented as a 16-bit value that combines with the base Bluetooth UUID to get the full 128-bit value.

CBUUID methods know these well-known values ​​and can automatically convert 16-bit values ​​to their 128-bit equivalent. CBUUID can also be initialized with a 128-bit value if you do not use known values ​​(Ie you created your own private services and characteristics)

For example, initializing a CBUUID with a CBUUID(string:"180F") is ok (this is a battery service), but the NSUUID(string:"180F") will fail because it needs all 128 bits.

When working with Core Bluetooth, you will use CBUUID for services and features. The NSUUID is used for the peripheral identifier, since it is just a MAC with no special meaning.

+11
source

All Articles