快速的CBUUID和NSUUID之间的差异 [英] Differences between CBUUID and NSUUID in swift

查看:111
本文介绍了快速的CBUUID和NSUUID之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CBUUID和NSUUID对象之间的区别在哪里?

Where are the differences between the CBUUID and the NSUUID object?

在不同情况下,我已经看到用两个对象填充scanForPeripheralsWithServices ...苹果期望使用CBUUID对象,所以我更喜欢使用这种类型?还是

I have seen to fill the scanForPeripheralsWithServices with both objects in different cases... Apple expect an CBUUID object so I would prefer to use this type or?

我的例子:

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

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

推荐答案

NSUUID是一个128位数字,用于唯一地标识对象,类型和其他项.可以按字节访问它,或者通常以字符串形式使用它-68753A44-4D6F-1226-9C60-0050E4C00067.该类包括用于创建随机UUID和使用专用值初始化的实例的方法.

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

蓝牙还为特征和服务使用128位标识符.蓝牙SIG定义了许多众所周知"的服务和特征.这些被表示为一个16位的值,该值与蓝牙基本UUID组合以获得完整的128位的值.

Bluetooth also uses 128 bit identifiers for characteristics and services. The Bluetooth SIG has defined many "well known" services and characteristics. These are represented as a 16 bit value which is combined with the Bluetooth base UUID to get the full 128 bit value.

CBUUID方法知道这些众所周知的值,并且可以将16位值自动转换为等效的128位值.如果您不使用众所周知的值(即您已经创建了自己的私有服务和特征),也可以使用128位值来初始化CBUUID.

The CBUUID methods are aware of these well known values and can automatically transform the 16 bit values into their 128 bit equivalent. A CBUUID can also be initialised with a 128 bit value if you aren't using well known values (I.e. You have created your own private services and characteristics)

例如用CBUUID(string:"180F")初始化CBUUID是可以的(这是电池服务),但是NSUUID(string:"180F")会失败,因为它需要全部128位.

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

使用Core Bluetooth时,您将使用CBUUID提供服务和特性. NSUUID用于外围设备标识符,因为那只是一个未定义特殊值的MAC.

When working with Core Bluetooth you will use CBUUID for services and characteristics. An NSUUID is used for the peripheral identifier since that is just a MAC with no special values defined.

这篇关于快速的CBUUID和NSUUID之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆