本文主要是介绍蓝牙中央管理器初始化详解,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
文章目录
- 蓝牙中央管理器初始化详解
- 1、接口解释
- 2、Options解释
- 1、CBCentralManagerOptionShowPowerAlertKey
- 2、CBCentralManagerOptionRestoreIdentifierKey
- 3、CBCentralManagerOptionDeviceAccessForMedia
蓝牙中央管理器初始化详解
1、接口解释
/*!* @method initWithDelegate:queue:options:** @param delegate The delegate that will receive central role events.* @param queue The dispatch queue on which the events will be dispatched.* @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.** @seealso CBCentralManagerOptionShowPowerAlertKey* @seealso CBCentralManagerOptionRestoreIdentifierKey**/
- (instancetype)initWithDelegate:(nullable id<CBCentralManagerDelegate>)delegatequeue:(nullable dispatch_queue_t)queueoptions:(nullable NSDictionary<NSString *, id> *)options NS_AVAILABLE(10_9, 7_0) NS_DESIGNATED_INITIALIZER;
delegate:CBCentralManager的回调代理
queue:CBCentralManager代理操作的所在队列,即delegate执行的所在队列。
options:其他选项,参考如下
2、Options解释
1、CBCentralManagerOptionShowPowerAlertKey
/*!* **@const** CBCentralManagerOptionShowPowerAlertKey** **@discussion** An NSNumber (Boolean) indicating that the system should, if Bluetooth is powered off when <code>CBCentralManager</code> is instantiated, display* a warning dialog to the user.** **@see** initWithDelegate:queue:options:**/
一个bool值,当蓝牙权限关闭的时候,如果CBCentralManager被初始化了,系统就是弹框提示用户蓝牙权限未开启
2、CBCentralManagerOptionRestoreIdentifierKey
/*!* **@const** CBCentralManagerOptionRestoreIdentifierKey** **@discussion** An NSString containing a unique identifier (UID) for the <code>CBCentralManager</code> that is being instantiated. This UID is used* by the system to identify a specific <code>CBCentralManager</code> instance for restoration and, therefore, must remain the same for* subsequent application executions in order for the manager to be restored.** **@see** initWithDelegate:queue:options:* **@seealso** centralManager:willRestoreState:**/
一个string,当应用程序使用CBCentralManager
与蓝牙设备进行通信时,如果设备支持(iOS 13及以上系统),可以在应用程序重启或系统重启后自动恢复与蓝牙设备的连接状态
3、CBCentralManagerOptionDeviceAccessForMedia
/*!* **@const** CBCentralManagerOptionDeviceAccessForMedia** **@discussion** A Boolean representing the CBCentralManager init purpose is for DeviceAccess for media only. This will limit the functionality of this* manager and only allow media device access without prompting the user for Bluetooth generic TCC.** **@see** initWithDelegate:queue:options:**/
CBCentralManagerOptionDeviceAccessForMedia
是一个在iOS中用于蓝牙相关操作的选项,它用于请求访问设备的蓝牙硬件以及媒体输入和输出设备。
在iOS 13及更高版本中,当你使用CBCentralManager
来管理蓝牙连接时,可以在初始化CBCentralManager
时,通过options
字典参数设置这个选项,以便让应用有权访问蓝牙硬件。
请注意,CBCentralManagerOptionDeviceAccessForMedia
是一个特定于iOS的选项,并不存在于其他操作系统上的Core Bluetooth框架中。因此,如果你在开发非iOS设备的应用,这个选项将不可用。
这篇关于蓝牙中央管理器初始化详解的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!