只需要把蓝牙设备信息传入即可 (测试蓝牙打印机可行)
+ (NSString *)getMacWithperipheral:(CBPeripheral *)peripheral {
NSString *value = @"000000000000";
NSMutableString *macString = [[NSMutableString alloc] init];
for (CBService *service in peripheral.services) {
for (CBCharacteristic *characteristic in service.characteristics) {
if ([characteristic.UUID.UUIDString isEqualToString:@"2A25"]) {
value = [[NSString alloc] initWithData:characteristic.value encoding:NSUTF8StringEncoding];
NSLog(@"%@", value);
}
}
}
[macString appendString:[[value substringWithRange:NSMakeRange(0, 2)] uppercaseString]];
[macString appendString:@":"];
[macString appendString:[[value substringWithRange:NSMakeRange(2, 2)] uppercaseString]];
[macString appendString:@":"];
[macString appendString:[[value substringWithRange:NSMakeRange(4, 2)] uppercaseString]];
[macString appendString:@":"];
[macString appendString:[[value substringWithRange:NSMakeRange(6, 2)] uppercaseString]];
[macString appendString:@":"];
[macString appendString:[[value substringWithRange:NSMakeRange(8, 2)] uppercaseString]];
[macString appendString:@":"];
[macString appendString:[[value substringWithRange:NSMakeRange(10, 2)] uppercaseString]];
NSLog(@"mac == %@",macString);
return macString;
}
网友评论