强烈建议大家把 CBCentralManager.h 里面的代理方法全部看一遍(就是翻译一遍,别偷懒)。@file CBCentralManager.h

/*先注释再编写

 * @file CBCentralManager.h

 * @framework CoreBluetooth

 *

 *  @discussion Entry point to the central role.

 *

 * @copyright 2011 Apple, Inc. All rights reserved.

 */

#ifndef _CORE_BLUETOOTH_H_

#warning Please do not import this header file directly. Use <CoreBluetooth/CoreBluetooth.h> instead.

#endif

#import <CoreBluetooth/CBDefines.h>

#import <CoreBluetooth/CBAdvertisementData.h>

#import <CoreBluetooth/CBCentralManagerConstants.h>

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN //NS假设null开始

 

/*!

 *  @enum CBCentralManagerState//中心控制管理者状态

 *

 *  @discussion Represents the current state of a CBCentralManager. //讨论了CB CentralManager的当前状态。

 *

 *  @constant CBCentralManagerStateUnknown       State unknown, update imminent.

 *  @constant CBCentralManagerStateResetting     The connection with the system service was momentarily lost, update imminent.

 *  @constant CBCentralManagerStateUnsupported   The platform doesn't support the Bluetooth Low Energy Central/Client role.

 *  @constant CBCentralManagerStateUnauthorized  The application is not authorized to use the Bluetooth Low Energy Central/Client role.

 *  @constant CBCentralManagerStatePoweredOff    Bluetooth is currently powered off.

 *  @constant CBCentralManagerStatePoweredOn     Bluetooth is currently powered on and available to use.

 *

 */

typedef NS_ENUM(NSInteger, CBCentralManagerState) {

CBCentralManagerStateUnknown = 0,//CB中央管理器状态未知= 0

CBCentralManagerStateResetting,//CB中央管理器状态重置

CBCentralManagerStateUnsupported,//CB中央管理器不支持的状态

CBCentralManagerStateUnauthorized,//未经授权的CB中央管理器状态

CBCentralManagerStatePoweredOff,//CB中央管理器关闭状态

CBCentralManagerStatePoweredOn,//CB中央管理器启动状态

};

@protocol CBCentralManagerDelegate;

@class CBUUID, CBPeripheral;

/*!

 *  @class CBCentralManager

 *

 *  @discussion Entry point to the central role. Commands should only be issued when its state is <code>CBCentralManagerStatePoweredOn</code>.//@discussion入口点的中心角色。命令只能发布其状态时<代码> CBCentralManagerStatePoweredOn > < /代码。

 *

 */

NS_CLASS_AVAILABLE(10_7, 5_0)

CB_EXTERN_CLASS @interface CBCentralManager : NSObject

 

/*!

 *  @property delegate

 *

 *  @discussion The delegate object that will receive central events.//讨论接收中心事件的委托对象。

 *

 */

@property(assign, nonatomic, nullable) id<CBCentralManagerDelegate> delegate;

 

/*!

 *  @property state//状态

 *

 *  @discussion The current state of the central, initially set to <code>CBCentralManagerStateUnknown</code>. Updates are provided by required//讨论当前状态的中央,最初设置为<代码> CBCentralManagerStateUnknown > < /代码。更新提供必需的

 *              delegate method {@link centralManagerDidUpdateState:}.//代理 方法 连接 中央管理器所做的更新状态

 *

 */

@property(readonly) CBCentralManagerState state;//状态只读

 

/*!

 *  @property isAdvertising//是广告

 *

 *  @discussion Whether or not the central is currently scanning.//讨论是否中央目前扫描。

 *

 */

@property(readonly) BOOL isScanning NS_AVAILABLE(NA, 9_0);

 

/*!

 *  @method initWithDelegate:queue://方法initWithDelegate:队列:

 *

 *  @param delegate The delegate that will receive central role events.//参数代表接收中心作用事件委托。

 *  @param queue    The dispatch queue on which the events will be dispatched.//param队列的调度队列事件将派遣。

 *

 *  @discussion     The initialization call. The events of the central role will be dispatched on the provided queue.//讨论了初始化。事件的核心作用将派遣提供队列。

 *                  If <i>nil</i>, the main queue will be used.//如果<我> nil < / i >,主队列将被使用。

 *

 */

- (instancetype)initWithDelegate:(nullable id<CBCentralManagerDelegate>)delegate

  queue:(nullable dispatch_queue_t)queue;

 

/*!

 *  @method initWithDelegate:queue:options://方法initWithDelegate:队列:选项:

 *

 *  @param delegate The delegate that will receive central role events.//参数代表接收中心作用事件委托。

 *  @param queue    The dispatch queue on which the events will be dispatched.//param队列的调度队列事件将派遣。

 *  @param options  An optional dictionary specifying options for the manager.//参数选项指定一个可选的词典选项的经理。

 *

 *  @discussion     The initialization call. The events of the central role will be dispatched on the provided queue.//讨论了初始化。事件的核心作用将派遣提供队列。

 *                  If <i>nil</i>, the main queue will be used.//如果<我> nil < / i >,主队列将被使用。

 *

 * @seealso CBCentralManagerOptionShowPowerAlertKey//参见CB AlertKey中央管理器选项显示力量

 * @seealso CBCentralManagerOptionRestoreIdentifierKey//参见CB恢复IdentifierKey中央管理器选项

 *

 */

- (instancetype)initWithDelegate:(nullable id<CBCentralManagerDelegate>)delegate

  queue:(nullable dispatch_queue_t)queue

options:(nullable NSDictionary<NSString *, id> *)options NS_AVAILABLE(NA, 7_0) NS_DESIGNATED_INITIALIZER;

 

/*!

 *  @method retrievePeripheralsWithIdentifiers://方法检索外围设备标识符:

 *

 *  @param identifiers A list of <code>NSUUID</code> objects.//参数标识符的列表<代码> NSUUID > < /代码对象

 *

 *  @discussion Attempts to retrieve the <code>CBPeripheral</code> object(s) with the corresponding <i>identifiers</i>.

 *//讨论试图检索<代码> CBPeripheral > < /代码对象(s)与相应的<我> < / i >标识符。

 * @return A list of <code>CBPeripheral</code> objects.//返回一个列表的<代码> CBPeripheral > < /代码对象。

 *

 */

- (NSArray<CBPeripheral *> *)retrievePeripheralsWithIdentifiers:(NSArray<NSUUID *> *)identifiers NS_AVAILABLE(NA, 7_0);

 

/*!

 *  @method retrieveConnectedPeripheralsWithServices//方法检索连接外围设备与服务

 *

 *  @discussion Retrieves all peripherals that are connected to the system and implement any of the services listed in <i>serviceUUIDs</i>.//讨论检索所有外围设备连接到系统和实现任何的服务列在<我> < / i >服务uuid

 * Note that this set can include peripherals which were connected by other applications, which will need to be connected locally//注意,这个集合包括外围设备连接的其他应用程序,将需要在本地连接

 * via {@link connectPeripheral:options:} before they can be used.//通过{ @link connectPeripheral:选择:}才可以使用。

 *

 * @return A list of <code>CBPeripheral</code> objects.//返回一个列表的<代码> CBPeripheral > < /代码对象。

 *

 */

- (NSArray<CBPeripheral *> *)retrieveConnectedPeripheralsWithServices:(NSArray<CBUUID *> *)serviceUUIDs NS_AVAILABLE(NA, 7_0);

 

/*!

 *  @method scanForPeripheralsWithServices:options://方法扫描外围设备与服务:选项:

 *

 *  @param serviceUUIDs A list of <code>CBUUID</code> objects representing the service(s) to scan for.//param服务uuid的列表<代码> CBUUID > < /代码对象代表服务(s)扫描。

 *  @param options      An optional dictionary specifying options for the scan.//参数选项指定一个可选的词典选项扫描。

 *

 *  @discussion         Starts scanning for peripherals that are advertising any of the services listed in <i>serviceUUIDs</i>. Although strongly discouraged,//讨论开始扫描的外设广告的任何服务列在<我> serviceUUIDs < / i >。虽然强烈的沮丧,

 *                      if <i>serviceUUIDs</i> is <i>nil</i> all discovered peripherals will be returned. If the central is already scanning with different//如果<我> serviceUUIDs < / i > <我>零< / i >将返回所有发现的外围设备。如果中央已经扫描与不同

 *                      <i>serviceUUIDs</i> or <i>options</i>, the provided parameters will replace them.//服务uuid < / i >或<我> < / i >选项,将取代他们所提供的参数。

 *                      Applications that have specified the <code>bluetooth-central</code> background mode are allowed to scan while backgrounded, with two//应用程序指定的<代码> bluetooth-central < /代码>背景模式允许扫描末尾时,有两个

 *                      caveats: the scan must specify one or more service types in <i>serviceUUIDs</i>, and the <code>CBCentralManagerScanOptionAllowDuplicatesKey</code>//警告:扫描必须指定一个或多个服务类型在<我> < / i >服务uuid、和<代码> CB中央管理器扫描选项允许重复关键代码> < /

 *                      scan option will be ignored.//扫描选项将被忽略。

 *

 *  @see                centralManager:didDiscoverPeripheral:advertisementData:RSSI://看到中央管理器:发现外围:广告数据:RSSI:

 *  @seealso            CBCentralManagerScanOptionAllowDuplicatesKey//参见CB中央管理器扫描选项允许复制钥匙

 * @seealso CBCentralManagerScanOptionSolicitedServiceUUIDsKey//参见CB中央管理器请求服务uuid键扫描选项

 *

 */

- (void)scanForPeripheralsWithServices:(nullable NSArray<CBUUID *> *)serviceUUIDs options:(nullable NSDictionary<NSString *, id> *)options;

 

/*!

 *  @method stopScan://方法停止扫描:

 *

 *  @discussion Stops scanning for peripherals.//讨论了扫描外围设备。

 *

 */

- (void)stopScan;

 

/*!

 *  @method connectPeripheral:options://方法连接外围:选项:

 *

 *  @param peripheral   The <code>CBPeripheral</code> to be connected.//param外围<代码> CB外围> < /代码被连接。

 *  @param options      An optional dictionary specifying connection behavior options.//参数选项指定一个可选的词典连接行为选项。

 *

 *  @discussion         Initiates a connection to <i>peripheral</i>. Connection attempts never time out and, depending on the outcome, will result//讨论发起一个连接到<我> < / i >外围。连接尝试从来没有时间出去,根据结果,将结果

 *                      in a call to either {@link centralManager:didConnectPeripheral:} or {@link centralManager:didFailToConnectPeripheral:error:}.//在调用{ @link中央管理器:连接外围:}或{ @link中央管理器:外围连接失败:错误:}。

 *                      Pending attempts are cancelled automatically upon deallocation of <i>peripheral</i>, and explicitly via {@link cancelPeripheralConnection}.等待尝试取消自动回收的<我> < / i >外围,并通过{ @link取消外围连接}明确。

 *

 *  @see                centralManager:didConnectPeripheral://看到中央管理器:连接周边:

 *  @see                centralManager:didFailToConnectPeripheral:error://看到中央管理器:外围连接失败:错误:

 *  @seealso            CBConnectPeripheralOptionNotifyOnConnectionKey//参见CB连接外围选项通知连接的关键

 *  @seealso            CBConnectPeripheralOptionNotifyOnDisconnectionKey//参见CB连接外围选项通知断开关键

 *  @seealso            CBConnectPeripheralOptionNotifyOnNotificationKey//参见CB连接外围选项通知通知关键

 *

 */

- (void)connectPeripheral:(CBPeripheral *)peripheral options:(nullable NSDictionary<NSString *, id> *)options;

 

/*!

 *  @method cancelPeripheralConnection://方法取消外围连接:

 *

 *  @param peripheral   A <code>CBPeripheral</code>.//param外围<代码> CBPeripheral > < /代码。

 *

 *  @discussion         Cancels an active or pending connection to <i>peripheral</i>. Note that this is non-blocking, and any <code>CBPeripheral</code>//讨论取消一个活动或等待连接到<我> < / i >外围。注意,这是阻塞,任何<代码> CBPeripheral > < /代码

 *                      commands that are still pending to <i>peripheral</i> may or may not complete.//命令,仍悬而未决的<我> < / i >外围可能或不可能完成。

 *

 *  @see                centralManager:didDisconnectPeripheral:error://看到中央管理器:断开外围:错误:

 *

 */

- (void)cancelPeripheralConnection:(CBPeripheral *)peripheral;

 

@end

 

 

/*!

 *  @protocol CBCentralManagerDelegate//CB中央管理器委托协议

 *

 *  @discussion The delegate of a {@link CBCentralManager} object must adopt the <code>CBCentralManagerDelegate</code> protocol.//讨论委托的CB中央管理器} { @链接对象必须采用<代码> CB中央管理器委托代码> < /协议。 The

 *              single required method indicates the availability of the central manager, while the optional methods allow for the discovery and//所需的单一方法表明中央管理器的可用性,同时允许发现和可选的方法

 *              connection of peripherals.//连接的外围设备。

 *

 */

@protocol CBCentralManagerDelegate <NSObject>

 

@required

 

/*!

 *  @method centralManagerDidUpdateState://方法是中央管理器更新状态:

 *

 *  @param central  The central manager whose state has changed.//param中央中央管理器的状态已经改变了。

 *

 *  @discussion     Invoked whenever the central manager's state has been updated. Commands should only be issued when the state is//讨论当中央管理器调用的状态已更新。只能状态时发出的命令

 *                  <code>CBCentralManagerStatePoweredOn</code>.//<代码> CB中央管理器状态启动> < /代码。 A state below <code>CBCentralManagerStatePoweredOn</code>//状态下<代码> CB中央管理器状态启动代码> < /

 *                  implies that scanning has stopped and any connected peripherals have been disconnected. If the state moves below//意味着扫描已经停止和任何连接外围设备已经断开连接。如果在移动状态下

 *                  <code>CBCentralManagerStatePoweredOff</code>, //CB中央管理器关闭状态 all <code>CBPeripheral</code> objects obtained from this central//所有CB 外围的对象从这个中心获得

 *                  manager become invalid and must be retrieved or discovered again.//经理再次成为无效的和必须检索或发现。

 *

 *  @see            state//观察,状态

 *

 */

- (void)centralManagerDidUpdateState:(CBCentralManager *)central;

 

@optional

 

/*!

 *  @method centralManager:willRestoreState://中央管理器方法:将恢复状态:

 *

 *  @param central      The central manager providing this information.//param中央中央管理器提供这些信息。

 *  @param dict A dictionary containing information about <i>central</i> that was preserved by the system at the time the app was terminated.//param dict字典包含<我> < / i >中部信息保存的系统应用时终止。

 *

 *  @discussion For apps that opt-in to state preservation and restoration, this is the first method invoked when your app is relaunched into//讨论应用程序选择国家保护和恢复,这是第一个方法调用应用程序重新启动时

 * the background to complete some Bluetooth-related task. Use this method to synchronize your app's state with the state of the//完成一些Bluetooth-related任务的背景。使用这种方法同步应用程序的状态的状态

 * Bluetooth system.//蓝牙系统

 *

 *  @seealso            CBCentralManagerRestoredStatePeripheralsKey;//参见CB中央管理器恢复国家外围设备的关键;

 *  @seealso            CBCentralManagerRestoredStateScanServicesKey;//参见CB中央管理器恢复状态扫描服务的关键;

 *  @seealso            CBCentralManagerRestoredStateScanOptionsKey;//参见CB中央管理器恢复状态扫描选项键;

 *

 */

- (void)centralManager:(CBCentralManager *)central willRestoreState:(NSDictionary<NSString *, id> *)dict;

 

/*!

 *  @method centralManager:didDiscoverPeripheral:advertisementData:RSSI://中央管理器方法:发现外围:广告数据:RSSI:

 *

 *  @param central              The central manager providing this update.//param中央中央管理器提供此更新。

 *  @param peripheral           A <code>CBPeripheral</code> object.//param外围<代码> CBPeripheral > < /代码对象。

 *  @param advertisementData    A dictionary containing any advertisement and scan response data.//param广告数据字典包含任何广告和扫描响应数据。

 *  @param RSSI                 The current RSSI of <i>peripheral</i>, in dBm. A value of <code>127</code> is reserved and indicates the RSSI//param RSSI的当前RSSI <我> < / i >外围,dBm。值<代码> 127 > < /代码保留和RSSI表示

 * was not available.//没有可用的。

 *

 *  @discussion                 This method is invoked while scanning, upon the discovery of <i>peripheral</i> by <i>central</i>. A discovered peripheral must//讨论这个方法被调用时扫描,发现<我> < / i >外围的<我> < / i >中部。发现外围必须

 *                              be retained in order to use it; otherwise, it is assumed to not be of interest and will be cleaned up by the central manager. //被保留,为了使用它;否则,它假定不感兴趣的,将由中央管理器清理。For

 *                              a list of <i>advertisementData</i> keys, see {@link CBAdvertisementDataLocalNameKey} and other similar constants.//<我>广告列表数据< / i >键,看到CB广告数据本地名称键} { @联系和其他类似的常数。

 *

 *  @seealso                    CBAdvertisementData.h//参见CBAdvertisementData.h

 *

 */

- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *, id> *)advertisementData RSSI:(NSNumber *)RSSI;

 

/*!

 *  @method centralManager:didConnectPeripheral://中央管理器方法:连接周边:

 *

 *  @param central      The central manager providing this information.//param中央中央管理器提供这些信息。

 *  @param peripheral   The <code>CBPeripheral</code> that has connected.//param外围<代码> CB外围连接> < /代码。

 *

 *  @discussion         This method is invoked when a connection initiated by {@link connectPeripheral:options:} has succeeded.//讨论时调用此方法连接由{ @链接连接外围:选项:}已经成功了。

 *

 */

- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral;

 

/*!

 *  @method centralManager:didFailToConnectPeripheral:error://方法中央管理器:外围连接失败:错误:

 *

 *  @param central      The central manager providing this information.param中央中央管理器提供这些信息。

 *  @param peripheral   The <code>CBPeripheral</code> that has failed to connect.//param外围<代码> CB外围> < /代码,连接失败。

 *  @param error        The cause of the failure.//参数错误失败的原因。

 *

 *  @discussion         This method is invoked when a connection initiated by {@link connectPeripheral:options:} has failed to complete. As connection attempts do not//讨论时调用此方法连接由{ @链接连接外围:选项:}未能完成。作为连接尝试

 *                      timeout, the failure of a connection is atypical and usually indicative of a transient issue.//超时、失败的典型连接,通常表明一个瞬态问题。

 *

 */

- (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(nullable NSError *)error;

 

/*!

 *  @method centralManager:didDisconnectPeripheral:error://中央管理器方法:断开外围:错误:

 *

 *  @param central      The central manager providing this information.//param中央中央管理器提供这些信息。

 *  @param peripheral   The <code>CBPeripheral</code> that has disconnected.//param外围<代码> CB外围> < /代码已经断开连接

 *  @param error        If an error occurred, the cause of the failure.//参数错误,如果一个错误发生,失败的原因。

 *

 *  @discussion         This method is invoked upon the disconnection of a peripheral that was connected by {@link connectPeripheral:options:}. If the disconnection

 *                      was not initiated by {@link cancelPeripheralConnection}, the cause will be detailed in the <i>error</i> parameter. Once this method has been//讨论这个方法被调用的断开连接的外围{ @链接连接外围:选项:}。如果断开

 *                      called, no more methods will be invoked on <i>peripheral</i>'s <code>CBPeripheralDelegate</code>.

 *//叫,没有更多的方法将被调用<我> < / i >外围的<代码> CB外围委托> < /代码。

 */

- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(nullable NSError *)error;

 

@end

 

NS_ASSUME_NONNULL_END

 

原文地址:https://www.cnblogs.com/gaozhang12345/p/5856728.html