Framework---Core Bluetooth(Core Bluetooth 框架)
Communicate with Bluetooth 4.0 low-energy devices.(用于與藍(lán)牙4.0低能耗設(shè)備之間的溝通)
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.(核心藍(lán)牙框架提供了您的應(yīng)用程序需要與藍(lán)牙低能量無線技術(shù)裝備的通信類)
Do not subclass any of the classes of the Core Bluetooth framework. Overriding these classes is unsupported and results in undefined behavior.(不要將核心藍(lán)牙框架的任何類歸為子類,不支持這些類并導(dǎo)致未定義的行為)
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之后如果要使用藍(lán)牙就必需要在 info.plist 加入NSBluetoothPeripheralUsageDescription 這個(gè)描述,不然就會崩潰)
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 類代表屬性協(xié)議(ATT)讀寫遠(yuǎn)程中央設(shè)備的請求(通過CBCentral對象表示)遠(yuǎn)程中心使用這些ATT請求讀寫附近外設(shè)的特征值(由CBPeripheralManager對象表示)衷敌。附近的外設(shè)勿侯,另一方面,使用CBATTRequest對象的特征來適當(dāng)?shù)捻憫?yīng)讀寫請求缴罗,使用cbperipheralmanager類的響應(yīng)方法助琐。)
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是一個(gè)抽象的基本類,定義對象集合的公共行為面氓,該對象集合表示外設(shè)提供的服務(wù)方面弓柱。)
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類表示遠(yuǎn)程中心設(shè)備在app上使用CBPeripheralManager 這個(gè)類去連接一個(gè)外圍設(shè)備(好難翻譯啊)侧但。遠(yuǎn)程中心是由通用唯一標(biāo)識符(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對象用于管理發(fā)現(xiàn)或連接的遠(yuǎn)程外圍設(shè)備(由CBPeripheral對象表示)航罗,包括掃描禀横,發(fā)現(xiàn)和連接廣告外設(shè)。)
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代表外圍的服務(wù)的更多信息粥血。特別是CBCharacteristic對象代表一個(gè)遠(yuǎn)程外圍的服務(wù)特點(diǎn)(遠(yuǎn)程外圍設(shè)備都由CBPeripheral對象表示)柏锄。一個(gè)特性包含一個(gè)值和描述該值的任意數(shù)量的描述符酿箭。特性的屬性決定了如何使用該特性的值以及描述符如何被訪問。)
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對象代表一個(gè)遠(yuǎn)程外圍的特征描述符(遠(yuǎn)程外圍設(shè)備都由CBPeripheral對象表示)缭嫡。描述符提供有關(guān)特征值的進(jìn)一步信息。例如抬闷,它們可以描述人類可讀的形式的值妇蛀,并描述如何為呈現(xiàn)目的格式化值。特征描述符還指示特征值是否配置在服務(wù)器(外圍設(shè)備)上笤成,以便在特征變化值指示或通知客戶端(中央)時(shí)评架。)
CBManager
The abstract base class for Core Bluetooth manager objects (central and peripheral).(核心藍(lán)牙管理器對象(中央和外圍)的抽象基類)
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對象代表一個(gè)地方周圍的服務(wù)特點(diǎn)(本地外圍設(shè)備都由CBPeripheralManager對象表示)。這類增加寫訪問的許多屬性繼承自CBCharacteristic類炕泳。)
CBMutableDescriptor
CBMutableDescriptor objects represent the descriptors of a local peripheral’s characteristic (local peripheral devices are represented by CBPeripheralManager objects).(CBMutableDescriptor對象代表一個(gè)地方周圍的特征描述符(本地外圍設(shè)備都由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