-
Notifications
You must be signed in to change notification settings - Fork 1k
运行时参数的设置
liuyanwei edited this page Sep 29, 2015
·
1 revision
原生corebluetooth在使用时可以设置一些参数,babybluetooth也支持通过函数,去设置corebluetooth的运行时参数。
//设置蓝牙运行时的参数
-(void)setBabyOptionsWithScanForPeripheralsWithOptions:(NSDictionary *) scanForPeripheralsWithOptions
connectPeripheralWithOptions:(NSDictionary *) connectPeripheralWithOptions
scanForPeripheralsWithServices:(NSArray *)scanForPeripheralsWithServices
discoverWithServices:(NSArray *)discoverWithServices
discoverWithCharacteristics:(NSArray *)discoverWithCharacteristics;
//设置蓝牙运行时的参数 channel版
-(void)setBabyOptionsAtChannel:(NSString *)channel
scanForPeripheralsWithOptions:(NSDictionary *) scanForPeripheralsWithOptions
connectPeripheralWithOptions:(NSDictionary *) connectPeripheralWithOptions
scanForPeripheralsWithServices:(NSArray *)scanForPeripheralsWithServices
discoverWithServices:(NSArray *)discoverWithServices
discoverWithCharacteristics:(NSArray *)discoverWithCharacteristics;
使用示例:
/*设置babyOptions
参数分别使用在下面这几个地方,若不使用参数则传nil
- [centralManager scanForPeripheralsWithServices:scanForPeripheralsWithServices options:scanForPeripheralsWithOptions];
- [centralManager connectPeripheral:peripheral options:connectPeripheralWithOptions];
- [peripheral discoverServices:discoverWithServices];
- [peripheral discoverCharacteristics:discoverWithCharacteristics forService:service];
该方法支持channel版本:
[baby setBabyOptionsAtChannel:<#(NSString *)#> scanForPeripheralsWithOptions:<#(NSDictionary *)#> connectPeripheralWithOptions:<#(NSDictionary *)#> scanForPeripheralsWithServices:<#(NSArray *)#> discoverWithServices:<#(NSArray *)#> discoverWithCharacteristics:<#(NSArray *)#>]
*/
//扫描选项->CBCentralManagerScanOptionAllowDuplicatesKey:忽略同一个Peripheral端的多个发现事件被聚合成一个发现事件
NSDictionary *scanForPeripheralsWithOptions = @{CBCentralManagerScanOptionAllowDuplicatesKey:@YES};
/*连接选项-> 只在非后台模式下才起作用
CBConnectPeripheralOptionNotifyOnConnectionKey :当应用挂起时,如果有一个连接成功时,如果我们想要系统为指定的peripheral显示一个提示时,就使用这个key值。
CBConnectPeripheralOptionNotifyOnDisconnectionKey :当应用挂起时,如果连接断开时,如果我们想要系统为指定的peripheral显示一个断开连接的提示时,就使用这个key值。
CBConnectPeripheralOptionNotifyOnNotificationKey:
当应用挂起时,使用该key值表示只要接收到给定peripheral端的通知就显示一个提
*/
NSDictionary *connectOptions = @{CBConnectPeripheralOptionNotifyOnConnectionKey:@YES,
CBConnectPeripheralOptionNotifyOnDisconnectionKey:@YES,
CBConnectPeripheralOptionNotifyOnNotificationKey:@YES};
[baby setBabyOptionsAtChannel:channelOnPeropheralView scanForPeripheralsWithOptions:scanForPeripheralsWithOptions connectPeripheralWithOptions:connectOptions scanForPeripheralsWithServices:nil discoverWithServices:nil discoverWithCharacteristics:nil];