Framework---Core Bluetooth(Core Bluetooth 框架)
Communicate with Bluetooth 4.0 low-energy devices.(用于与蓝牙4.0低能耗设备之间的沟通)
Overview---概述
The Core Bluetooth framework provides the classes needed for your apps to communicate with devices that are equipped with Bluetooth low energy wireless technology.(核心蓝牙框架提供了您的应用程序需要与蓝牙低能量无线技术装备的通信类)
Do not subclass any of the classes of the Core Bluetooth framework. Overriding these classes is unsupported and results in undefined behavior.(不要将核心蓝牙框架的任何类归为子类,不支持这些类并导致未定义的行为)
Important ---重要提示
An iOS app linked on or after iOS 10.0 must include in its Info.plist file the usage description keys for the types of data it needs to access or it will crash. To access Bluetooth peripheral data specifically, it must include NSBluetoothPeripheralUsageDescription.(iOS 10.0之后如果要使用蓝牙就必需要在 info.plist 加入NSBluetoothPeripheralUsageDescription 这个描述,不然就会崩溃)
Classes---类别
CBATTRequest
The CBATTRequest class represents Attribute Protocol (ATT) read and write requests from remote central devices (represented by CBCentral objects). Remote centrals use these ATT requests to read and write characteristic values on local peripherals (represented by CBPeripheralManager objects). Local peripherals, on the other hand, use the properties of CBATTRequest objects to respond to the read and write requests appropriately, using the respond(to:withResult:) method of the CBPeripheralManager class.(CBATTRequest 类代表属性协议(ATT)读写远程中央设备的请求(通过CBCentral对象表示)远程中心使用这些ATT请求读写附近外设的特征值(由CBPeripheralManager对象表示)。附近的外设,另一方面,使用CBATTRequest对象的特征来适当的响应读写请求,使用cbperipheralmanager类的响应方法。)
CBAttribute
CBAttribute is an abstract base class that defines behavior common to the collection of objects that represent aspects of services offered by a peripheral.(CBAttribute是一个抽象的基本类,定义对象集合的公共行为,该对象集合表示外设提供的服务方面。)
CBCentral
The CBCentral class represents remote central devices that have connected to an app implementing the peripheral role on a local device. That is, when you are implementing the peripheral role using the CBPeripheralManager class, centrals that connect to your local peripheral are represented as CBCentral objects. Remote centrals are identified by universally unique identifiers (UUIDs), represented by NSUUID objects.(CBCentral类表示远程中心设备在app上使用CBPeripheralManager 这个类去连接一个外围设备(好难翻译啊)。远程中心是由通用唯一标识符(UUID),由NSUUID确定对象)
CBCentralManager
CBCentralManager objects are used to manage discovered or connected remote peripheral devices (represented by CBPeripheral objects), including scanning for, discovering, and connecting to advertising peripherals.(CBCentralManager对象用于管理发现或连接的远程外围设备(由CBPeripheral对象表示),包括扫描,发现和连接广告外设。)
CBCharacteristic
CBCharacteristic and its subclass CBMutableCharacteristic represent further information about a peripheral’s service. CBCharacteristic objects in particular represent the characteristics of a remote peripheral’s service (remote peripheral devices are represented by CBPeripheral objects). A characteristic contains a single value and any number of descriptors describing that value. The properties of a characteristic determine how the value of the characteristic can be used and how the descriptors can be accessed.(CBCharacteristic及其亚类CBMutableCharacteristic代表外围的服务的更多信息。特别是CBCharacteristic对象代表一个远程外围的服务特点(远程外围设备都由CBPeripheral对象表示)。一个特性包含一个值和描述该值的任意数量的描述符。特性的属性决定了如何使用该特性的值以及描述符如何被访问。)
CBDescriptor
CBDescriptor and it subclass CBMutableDescriptor represent a descriptor of a peripheral’s characteristic. CBDescriptor objects in particular represent the descriptors of a remote peripheral’s characteristic (remote peripheral devices are represented by CBPeripheral objects). Descriptors provide further information about a characteristic’s value. For example, they may describe the value in human-readable form and describe how the value should be formatted for presentation purposes. Characteristic descriptors also indicate whether a characteristic’s value is configured on a server (a peripheral) to indicate or notify a client (a central) when the value of the characteristic changes.(CBDescriptor和它的子类CBMutableDescriptor代表一种的特征描述符。特别是CBDescriptor对象代表一个远程外围的特征描述符(远程外围设备都由CBPeripheral对象表示)。描述符提供有关特征值的进一步信息。例如,它们可以描述人类可读的形式的值,并描述如何为呈现目的格式化值。特征描述符还指示特征值是否配置在服务器(外围设备)上,以便在特征变化值指示或通知客户端(中央)时。)
CBManager
The abstract base class for Core Bluetooth manager objects (central and peripheral).(核心蓝牙管理器对象(中央和外围)的抽象基类)
CBMutableCharacteristic
CBMutableCharacteristic objects represent the characteristics of a local peripheral’s service (local peripheral devices are represented by CBPeripheralManager objects). This class adds write access to many of the properties in the CBCharacteristic class it inherits from.(CBMutableCharacteristic对象代表一个地方周围的服务特点(本地外围设备都由CBPeripheralManager对象表示)。这类增加写访问的许多属性继承自CBCharacteristic类。)
CBMutableDescriptor
CBMutableDescriptor objects represent the descriptors of a local peripheral’s characteristic (local peripheral devices are represented by CBPeripheralManager objects).(CBMutableDescriptor对象代表一个地方周围的特征描述符(本地外围设备都由CBPeripheralManager对象表示))
CBMutableService
The CBMutableService class adds write access to all of the properties in the CBService class it inherits from. You use this class to create a service or an included service on a local peripheral device (represented by a CBPeripheralManager object). After you create a service, you can add it to the peripheral’s local database using the add(_:) method of the CBPeripheralManager class. After you add a service to the peripheral’s local database, the service is cached and you can no longer make changes to it.
CBPeer
The CBPeer class is an abstract base class that defines common behavior for objects representing remote devices. You typically do not create instances of either CBPeer or its concrete subclasses. Instead, the system creates them for you during the process of peer discovery.
CBPeripheral
The CBPeripheral class represents remote peripheral devices that your app—by means of a central manager (an instance of CBCentralManager)—has discovered advertising or is currently connected to. Peripherals are identified by universally unique identifiers (UUIDs), represented by NSUUID objects. Peripherals may contain one or more services or provide useful information about their connected signal strength.
CBPeripheralManager
CBPeripheralManager objects are used to manage published services within the local peripheral device’s Generic Attribute Profile (GATT) database and to advertise these services to central devices (represented by CBCentral objects). While a service is in the database, it is visible to, and can be accessed by, any connected central. That said, if your app has not specified the bluetooth-peripheral background mode, the contents of its services become disabled when it is in the background or in a suspended state; any remote central trying to access the service’s characteristic value or characteristic descriptors receives an error.
CBService
CBService and its subclass CBMutableService represent a peripheral’s service—a collection of data and associated behaviors for accomplishing a function or feature of a device (or portions of that device). CBService objects in particular represent services of a remote peripheral device (represented by a CBPeripheral object). Services are either primary or secondary and may contain a number of characteristics or included services (references to other services).
CBUUID
Instances of the CBUUID class represent the 128-bit universally unique identifiers (UUIDs) of attributes used in Bluetooth low energy communication, such as a peripheral’s services, characteristics, and characteristic descriptors. This class provides a number of factory methods for dealing with long UUIDs when developing your app. For example, instead of passing around the string representation of a 128-bit Bluetooth low energy attribute in your code, you can create a CBUUID object that represents it, and pass that around instead.
Protocols
CBCentralManagerDelegate
The CBCentralManagerDelegate protocol defines the methods that a delegate of a CBCentralManager object must adopt. The optional methods of the protocol allow the delegate to monitor the discovery, connectivity, and retrieval of peripheral devices. The only required method of the protocol indicates the availability of the central manager, and is called when the central manager’s state is updated.
CBPeripheralDelegate
The delegate of a CBPeripheral object must adopt the CBPeripheralDelegate protocol. The delegate uses this protocol’s methods to monitor the discovery, exploration, and interaction of a remote peripheral’s services and properties. There are no required methods in this protocol.
CBPeripheralManagerDelegate
The delegate of a CBPeripheralManager object must adopt the CBPeripheralManagerDelegate protocol, a protocol consisting of numerous optional methods and one required method. The protocol’s optional methods are used by the delegate to verify publishing and advertising, and to monitor read, write, and subscription requests from remote central devices. The protocol’s required method, which indicates whether the peripheral manager is available, is called when the peripheral manager’s state is updated.
Reference
Core Bluetooth Constants
This document describes the constants found in the Core Bluetooth framework.
Core Bluetooth Enumerations
Structures
CBATTError
CBAttributePermissions
Values representing the read, write, and encryption permissions for a characteristic’s value.
CBCharacteristicProperties
Values representing the possible properties of a characteristic. Since characteristic properties can be combined, a characteristic may have multiple property values set.
CBError