欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

相关标签: ios