2018年7月25日 星期三

iOS read MAC address - chinese

https://www.jianshu.com/p/1d6a8fc8134f

1. After connection, read characteristic value
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral
 {
     peripheral.delegate = self;
    [peripheral discoverServices:@[[CBUUID UUIDWithString:@"180A"]]];
}

#pragma mark - CBPeripheralDelegate
- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error{
    CBService *service = peripheral.services.firstObject;
    [peripheral discoverCharacteristics:@[[CBUUID UUIDWithString:@"2A23"]] forService:service];
}

2.在扫描的过程中就获取设备的Mac地址
put the address to adv data - key:kCBAdvDataManufacturerData