ios 蓝牙 扫描到蓝牙设备的时候同时记录advertisementData和RSSI
程序员文章站
2022-03-20 22:46:58
/** didDiscoverPeripheral: peripheral: 扫描到的外设 advertisementData: 外设的广告介绍信息 RSSI: 外设信号强度 int类型 *///外设是不能自己创建的,只能通过扫描得到-(void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary&...
/**
didDiscoverPeripheral:
peripheral: 扫描到的外设
advertisementData: 外设的广告介绍信息
RSSI: 外设信号强度 int类型
*/
//外设是不能自己创建的,只能通过扫描得到
-(void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary<NSString *,id> *)advertisementData RSSI:(NSNumber *)RSSI{
ScanInfo *scanInfo = [[ScanInfo alloc] initWithPeripheral:peripheral number:RSSI];
if ([_scanArr containsObject:peripheral]) {
NSInteger index = [_scanArr indexOfObject:peripheral];
[_scanArr removeObjectAtIndex:index];
[_scanInfoArr removeObjectAtIndex:index];
}
[_scanInfoArr addObject:scanInfo];
[_scanArr addObject:peripheral];
self.scanBlock(peripheral);
}
@interface ScanInfo : NSObject
@property(nonatomic,strong)CBPeripheral *peripheral;
@property(nonatomic,strong)NSNumber *number;
- (instancetype)initWithPeripheral: (CBPeripheral *)peripheral number: (NSNumber *)number;
@end
@implementation ScanInfo
- (instancetype)initWithPeripheral: (CBPeripheral *)peripheral number: (NSNumber *)number
{
self = [super init];
if (self) {
_peripheral = peripheral;
_number = number;
}
return self;
}
@end
本文地址:https://blog.csdn.net/baidu_40537062/article/details/110563148
上一篇: AngularJS执行流程详解
下一篇: 第二天:图像标签及超链接的使用